# Include <iostream. h> Class A {public: A (int I) {A = I;} A () {A = 0; cout <"default constructor called. "<A <Endl ;}~ A () {cout <"destructor called. "<A <Endl;} void print () {cout <Endl;} PRIVATE: int A ;}; void main () {A [4], * P; int n = 1; P = A; For (INT I = 0; I <4; I ++) A [I] = a (++ N); for (I = 0; I <4; I ++) (p + I)-> Print ();} answer: default constructor called. 0 default constructor called. 0 default constructor called. 0 default constructor called. 0 destructor called. 2 destructor called. 3 destructor called. 4 destructor called. 5 2 3 4 5 destructor called. 5 destructor called. 4 destructor called. 3 destructor called. 2
Why does this result appear?
The preceding destructor is called because the original value is deleted after the value is assigned again, but the value in it has been modified.
Then, the following destructor is parsed at the end of the last one, because it is determined that the program is finished and then goes back to the structure.