1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
#include <iostream>

class X {
   public:
      X() {
	 std::cout << "an object of type X gets default-constructed"
	    << std::endl;
      }
      ~X() {
	 std::cout << "an object of type X gets destructed" << std::endl;
      }
};

class Y {
   public:
      Y() {
	 std::cout << "an object of type Y gets default-constructed"
	    << std::endl;
      }
      ~Y() {
	 std::cout << "an object of type Y gets destructed" << std::endl;
      }
};

class Z {
   public:
      Z() {
	 std::cout << "an object of type Z gets default-constructed"
	    << std::endl;
      }
      ~Z() {
	 std::cout << "an object of type Z gets destructed" << std::endl;
      }
   private:
      X x;
      Y y;
};

int main() {
   Z z; /* invokes compiler-provided default constructor */
}