我正在尝试构建一个具有字符矩阵的游戏.我正在尝试使用向量向量来构建我的矩阵.我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)