Containers for dynamically-allocated objects

Object-oriented programming relies heavily on using polymorphic base class references to manipulate objects of an entire class hierarchy. More often than not, these objects are dynamically allocated. When dealing with a whole collection of such objects, STL containers come a cropper; they store concrete objects of a single type and require copy or move semantics. It is impossible to define a single container that can store objects of different classes across a hierarchy. While you may store polymorphic base class pointers in containers, pointers are treated as POD-types and with little support for deep-copy semantics. The life cycle of dynamically-allocated objects is none of STL's business. But it ...

Get Learning Boost C++ Libraries now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.