繁体   English   中英

创建一个2D矢量数组

[英]creating a 2D array of vectors

我一直在尝试为游戏创建一个2D矢量数组。 这是我正在做的一个例子。

struct TILE {
    int a;
    char b;
    bool c;
};

TILE temp_tile;

std::vector<TILE> temp_vec_tile;
std::vector<std::vector<TILE>> tile;


for (int x = 0; x < 10; x++) {
    for (int y = 0; y < 10; y++) {

    temp_tile.a = x;
    temp_tile.b = "a";
    temp_tile.c = false;;

    temp_vec_tile.push_back(temp_tile);
    }

    tile.push_back(temp_vec_tile);
}

// Why does this not work?
int x = tile[3][5].a;

注意:我不想为此使用Boost。

谢谢

您不是每次都清除内部向量。 可能你想要的是将内部向量声明放在第一个for循环中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM