c++: can vector contain objects of type Derived?

No, the Derived objects will be sliced: all additional members will be discarded.

Instead of raw pointers, use std::vector<std::unique_ptr<Base> >.

Leave a Comment