The object does the function parameter//1 studies the copy constructs the//2 to study the constructor function, the destructor call Order//summary construction and the destructor call Order # include "iostream" using namespace Std;class abcd{// This () public:abcd (int A, int b, int c) {this->a = A;this->b = B;this->c = c;printf ("ABCD () construct, A:%d,b:%d,c: %d \ n ", This->a, This->b, this->c);} ~ABCD () {printf ("~abcd () construct,a:%d,b:%d,c:%d \ n", This->a, This->b, this->c);} int Geta () {return this->a;} Protected:private:int a;int b;int c;}; Class Mye{public:mye (): ABCD1 (1, 2, 3), ABCD2 (4, 5, 6), M (+) {cout << "MyD ()" << Endl;} ~mye () {cout << "~myd ()" << Endl;} Mye (const Mye & obj): ABCD1 (7, 8, 9), ABCD2 (Ten, One,), M (+) {printf ("MyD (const MyD & obj) \ n");} PROTECTED://PRIVATE:PUBLIC:ABCD ABCD1; The C + + compiler does not know how to construct abc1abcd abcd2;const int m;}; int dothing (Mye mye1) {printf ("dothing () mye1.abc1.a:%d \ n", Mye1.abcd1.getA ()); return 0;} int run2 () {Mye mye;dothing (mye); return 0;} int Run3 () {printf ("Run3 Start: \ n "); ABCD ABCD = ABCD (100, 200, 300); Initializes an object with a temporary object, it changes the temporary object to the beginning of theInitialized object without invoking the copy constructor, the temporary object does not have to assign itself to the other, and then destroy itself so troublesome.//ABCD (400, 500, 600); The life cycle of the temporary object is printf ("Run3 end\n"); return 0;} int main () {run2 ();//run3 (); System ("pause"); return 0;}
Output
C + + class construction destructor call sequence Training (review dedicated)