Awesome i'll research smart pointers then.However, this can only be achieved through pointers or references. Since you cannot store references in dynamic containers you need to work with pointers.
The three objects of the derived types has to be dynamically allocated. You are strongly advised to use smart pointers instead of raw pointers though, but which one to use depends on how the ownership of the object shall be handled.std::vector<CUnit *> units; units.push_back(new CUnitA); units.push_back(new CUnitB); units.push_back(new CUnitC);
So I can have a vector of groups, and within that vectors of units, does that massively affect memory usage?
Not saying anything about the design, but you certain can do that. Memory usage can mean different things though. Constant virtual dispatching if you're, say, iterating over the containers to call a virtual function on all units, may very well become a problem before the amount of memory used does. If you intend to use the type system to distinguish between similar units, then consider a data-driven approach instead. Do you really need the units to have different types instead of just having a single unit type with different data describing the type?
Plus I've been looking into save files and I wanted to clear up something there too as it links to the same issue.
When saving is it better to parse out all the variables in the classes and write them like XML (for example) and then populate in reverse when loading?
P.S. gotta go to work so it's going to be a late reply.
Serializing the data becomes a bigger problem if you, instead of using a data-driven approach with a single type, also have to determine the correct type within the language itself. Not only do you have to read the data from the external source, you also have to determine whether to call new on CUnitA, CUnitB or CUnitC on your data. Again, do you really need the different types?