如何将数据存储在 class 私有的 2D 向量中?

How to store data in a 2D vector within class private?

基本上我从 txt 文件中获取数据并将其放入一个 class 函数中的向量中,然后在另一个 class 函数中检索该数据 - 但我当我尝试构建时收到错误消息。

在我名为 'Level' 的 class 的私有区域中,我定义了一个结构:

struct largeTile
{
    int texture;
}

接下来在我的 class 私有区域 'Level' 我定义了一个 2D 向量来保存结构对象:

vector<vector<largeTile> > vvint(int BIG_TILE_ROWS, vector<largeTile>(int BIG_TILE_COLUMNS));

在名为 'Level' 的 class 中,我有一个函数可以使用 txt 文件中的结构对象填充向量数组:

for(int r = 0; r < vvint.size(); r++)
{
    for(int c = 0; c < vvint.at(0).size(); c++)
    {
        fileData >> vvint[r][c].texture;
    }
}

虽然我收到了这条构建消息,但我做错了什么?我已经将 class 类型定义为 'largeTile' 否?

错误:'((Level*)this)->Level::vvint' 没有 class 类型

您已将 vvint 声明为一个函数。我猜你的意思是

vector<vector<largeTile>> vvint = 
    vector<vector<largeTile>>(BIG_TILE_ROWS, vector<largeTile>(BIG_TILE_COLUMNS));

ROWS 个大小为 COLUMNS 的向量初始化它。