Home > Back-end >  The structure of the object and the destructor of the sequential relationship
The structure of the object and the destructor of the sequential relationship

Time:12-01

For the bosses to explain the basic principle of

1. In a class with another class as a member of
Structure members of the class to the first class
Destructor this class first, then analysis constitute member class

2. A class inherits from a parent class
To structure the parent class to first subclass
First destructor subclass destructor again parent

Heard that because of pressure from stack, but want to create the object if the heap area?
So because the stack characteristics of exactly right?

CodePudding user response:

With the stack doesn't matter much, this is determined by the compiler calls to order,

CodePudding user response:

Pressure stack out just stack operation, has nothing to do with pile area to create objects, the pressure out of the stack is not memory allocated on the stack and heap on the stack, is a kind of description of data structure.

CodePudding user response:

Inheritance:
Member variables of the parent class is inherited by subclasses to a certain extent a subclass of memory size has a parent class factors,
When the destructor opposite
Combination:
The same inheritance

How to inherit + combination, the class itself or the final structure, as for the composition and inheritance which first structure is determined by the compiler, most is my father class structure, again is a class member structure, finally its own structure,


CodePudding user response:

1. A class of another class as a member,
Structure members of the class to the first class
Destructor this class first, then analysis constitute member class
==================
This is not necessarily the? Depending on your member is declared in the class;
In many cases in the h file just statement; In the constructor definition, which first execute construction initialization; Then execute the constructor; Members in the constructor to create;

The destructor in the following order: and structure;
The destructor body; The constructor to initialize the inverse process; Base class destructor;
  • Related