簡體   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