click to close
S R T B H P N

CompObj.cpp, CompObj.txt, Code folder, Compound Objects webpage, Class Relationships webpage

Compound objects are objects that contain and use instances of other classes.
Of particular importance is the way they are initialized in constructor implementations.
That aspect is illustrated in this example.

All of the classes in this demo have correct copy, assignment, destruction, and move semantics, so we would normally defer to the compiler generated operations. However, for this demo we want to show how each of these methods are defined and show when they are invoked by writing from them to the console.

UML Diagram showing an abstract view of this code.

 ============================================
  Demonstrating Operation of Compound Object
 ============================================
  U default construction
  C default construction
  B default construction
  D default construction
  D using U
 ----------------------
  Running testFunction
 ----------------------
  C default construction
  B default construction
  D default construction
  C move construction
  B move construction
  D move construction
  D destruction
  B destruction
  C destruction
  D move assignment
  B move assignment
  C move assignment
  D destruction
  B destruction
  C destruction
 ----------------------------
  starting copy construction
 ----------------------------
  C copy construction
  B copy construction
  D copy construction
 ----------------------------
  starting move construction
 ----------------------------
  C move construction
  B move construction
  D move construction
 ----------------------------
  Demonstrating polymorphism
 ----------------------------
  C default construction
  B default construction
  Calling B::g()
  Calling D::g()
 ----------------------
  leaving main's scope
 ----------------------
  D destruction
  B destruction
  C destruction
  D destruction
  B destruction
  C destruction
  D destruction
  B destruction
  C destruction
  U destruction
Press any key to continue . . .