Say I have a member variable vector<bool> rightWall;. rightWall has width*height indices. I want to access a random index of rightWall. So I do:
index1=rand()%(width*height-1);
rightWall[index1]=true;
But I get Valgrind errors: Invalid read of size 8. rightWall was never initialized or anything, and I’m not sure it’s really supposed to, since its only bools. What can be the problem?
To get a vector of a certain size you need to initialize it like so:
or resize it: