小编Car*_*ist的帖子

初始化由类的构造函数内的向量组成的矩阵

我正在尝试构建一个具有字符矩阵的游戏.我正在尝试使用向量向量来构建我的矩阵.我game.h有这个:

#ifndef GAME_H
#define GAME_H
// includes
using namespace std;
class Game 
{
  private:
    int row;
    int col;
    vector<vector<char>>* matrix;
    // other atributtes

  public:
    Game();
    ~Game(){}
    // some functions
};
#endif
Run Code Online (Sandbox Code Playgroud)

在我的game.cpp:

Game::Game()
{
    this->col = 20;
    this->row = 20;
    // Initialize the matrix
    this->matrix = new vector<vector<char>>(this->col);
    for(int i = 0 ; i < this->col ; i++)
       this->matrix[i].resize(this->row, vector<char>(row));
    // Set all positions to be white spaces
    for(int i = 0 ; i <  this->col; …
Run Code Online (Sandbox Code Playgroud)

c++ class stdvector

6
推荐指数
1
解决办法
314
查看次数

标签 统计

c++ ×1

class ×1

stdvector ×1