I'm trying to declare a twodimensional array with a value int size
but I don't know how to do it.
I want to do this:
int size;
class tile {
public:
tile() : val( 0 ), blocked( false ) {}
unsigned int val;
bool blocked;
};
tile board[size][size];
Thanks for your help :)
std::vector< std::vector< tile> > board( size , std::vector<tile> ( size ) );
will do it.
Alternatively,
tile** board = new (tile*) [size]; //allocate the array as a whole
for (int i = 0; i < size; ++i) //now allocate each row in it
board[0] = new tile [size];
But vectors are definitely the way to go.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.