I'm trying to build a game which has a matrix of chars. I'm trying to use a vector of vectors to build my matrix. My game.h
has this:
#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
And in my 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; i++)
for(int j = 0 ; j < this->row ; j++)
this->matrix[i][j] = ' ';
}
It's giving me an error:
error: no match for ‘operator=’ (operand types are ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<char> > >::value_type {aka std::vector<char>}’ and ‘char’)
this->matrix[i][j] = ' ';
^~~
in the line:
this->matrix[i][j] = ' ';
I would like to know what's causing this and how can I set everything to be a whitespace in my constructor?