Composition “owns-a” C++

Composition in C++ is defined as implementing complex objects using simpler or smaller ones.

If A owns-a B, then generally:

  • B does not have an independent existence for A
  • If A dies, then B dies
  • If A is copied, B is copied as well (deep copy)

Typically, this is implemented in C++ via object fields.