I want to store multiple class types derived from the same base class in a single stl list.
If I use
list<BaseClass> L;
then my code compiles fine when I add any derived classes. However, it looks like my derived classes are automatically being casted down to the base type before being stored. Obviously I want to store the unique members of the derived types as well. How can I do this?
You have to use
But with this, you will have problems with exception safety (Where do you destroy the object when the list goes out of scope? What if some exception is thrown before?). So maybe this:
would be better. TR1 basic info can be found e.g. on wikipedia, its documentation
under the boost docs.