Quick Q: How do you have an STL container of polymorphic objects? -- StackOverflow
Quick A: Try vector<unique_ptr<base>>
by default.
What's the preferred C++ idiom to own a collection of polymorphic objects?
... I'm sure there's something related to move semantics in there (I could move the objects passed to
add_items()
to own them) but I still can't figure out how my collection would be declared.What is the C++ idiom for this sort of polymorphic ownership (particularly with STL containers)?