I'm going through a book and I've looked this up, but don't understand why (or maybe I have to) use reserve. Since it is a vector why is there a need to reserve memory? Is it just a way so that it doesn't double the memory off the heap or something (me guessing)?
here is the code I am looking at:
Code:
class Farm
{
public:
Farm(int spaces = 1);
//.... more stuff goes here
private:
vector<myFarmAnimalClassObject> m_farmAnimal;
};
//=============Constructor: reserve used below=========
Farm::Farm(int spaces)
{
m_farmAnimal.reserve(spaces) // <=== reserve?
}