I'm trying to initialize a private vector in a constructor. When I call resize before I push_back on the vector, I get a bunch of 0s when I call GameBoard::print(). When I move resize after I push_back the vector, GameBoard::print() outputs what I would expect. Can someone explain why it's doing that? And, do I need to even bother resizing vectors at all? (My goal is to store a great many of these vectors in a hashset for AI purposes).
When you resize a vector to a size that is larger than it's current size every new space created is assigned to a 0 to help prevent errors, when resizing you have the option of assigning these newly created spaces to something else using vec.resize(<size>, <assignment>);
vector's function member push_back(<val>)will increase the vectors storage size by +1 to add the new element...
So when you call resize() it'll setup the vector of your chosen size and set them all to 0's then when when you call push_back it does still add more values to the end of your vector, these are simply not shown because they're stored in vector position exceeding your boardsize because...
When you call push_back() first your size increase by +1 each time and the value given as the argument is assigned. Then when you call resize() nothing actually happens because your vector is already this size...
No problem pal (or at least no problem from me), That's what the forums are here for, I'm glad to say you had a well structured question with all the information we needed without just chucking in all the unnecessary extras, (thanks)...
Makes it easier for us to help (and more willing if things are nice and clear)