The Calling sequence of the constructor of the C ++ aggregate relationship class, and the aggregate Constructor
Indicates an aggregation relationship.
The following code is used to implement
1 # pragma once2 class Engine3 {4 public: 5 Engine (); 6 ~ Engine (); 7}; Engine. h 1 # include <iostream> 2 # include "Engine. h "3 using namespace std; 4 5 Engine: Engine () 6 {7 cout <" Call constructor: Engine () "<endl; 8} 9 10 Engine: :~ Engine () 11 {12 cout <"Call destructor :~ Engine () "<endl; 13} Engine. cpp 1 # pragma once 2 # include "Engine. h "3 4 class Car 5 {6 public: 7 Car (); 8 ~ Car (); 9 private: 10 Engine m_eCar; 11}; Car. h 1 # include <iostream> 2 # include "Car. h "3 using namespace std; 4 5 Car: Car () 6 {7 cout <" Call constructor: Car () "<endl; 8} 9 10 Car: :~ Car () 11 {12 cout <"Call the Destructor :~ Car () "<endl; 13} Car. cpp
From this we can see that the calling sequence of object constructor is the same as that of building a car. We can build an engine and other components before assembling a car, the calling of the Destructor is the same as disassembling a car. First, the outermost is opened, and then the inside is pulled.