Book Image

Learning Boost C++ Libraries

By : Arindam Mukherjee
Book Image

Learning Boost C++ Libraries

By: Arindam Mukherjee

Overview of this book

Table of Contents (19 chapters)
Learning Boost C++ Libraries
About the Author
About the Reviewers

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 is unwieldy to define a container of pointers whose lifetimes have to be managed separately without any help from the container.

The Boost Pointer Container library addresses these gaps by storing pointers to dynamically-allocated objects and deallocating...