C ++ _ Exercise - inherited _ structure initialization list

Structure initialization list


 

A member of the order of the objects constructed nothing to do with the initialization list, with the definition of the relevant order

 

. 1 #include <the iostream>
 2  
. 3  the using  namespace STD;
 . 4  
. 5  class info {
 . 6  public :
 . 7      info ( int A) {
 . 8          Age = A;
 . 9          COUT Age << << endl;
 10          COUT << " constructor automatically call " << endl;
 . 11       }
 12 is  
13 is      ~ info () {
 14          COUT << " destructor is automatically called " << endl;
 15     }
 16  
. 17  Private :
 18 is      int Age;
 . 19  };
 20 is  
21 is  class the INFO1 {
 22 is  public :
 23 is      the INFO1 ( int AG, info & A, info & B): info1_A (A), info1_B (B) {    // constructed object members nothing to do with the order of initialization list! ! 
24          info1_age = AG;
 25          COUT << " the INFO1 constructor " << endl;
 26 is      }
 27  
28      ~ the INFO1 () {
 29          COUT << " destructor is automatically called ."<< endl;
 30      }
 31 is  
32  
33 is  Private :
 34 is      int info1_age;
 35      info info1_A;
 36      info info1_B;   // with the defined order dependent! ! 
37 [  };
 38 is  
39  
40  int main ( void ) {
 41 is  
42 is  
43 is      info A ( . 1 ), B ( 2 );
 44 is  
45      the INFO1 .INFO_ ( . 1 , A, B);   // must be configured before creating the two objects info! 
46 is  
47      System ( " PAUSE ");
48 
49     return 0;
50 }

 

notes


 

Guess you like

Origin www.cnblogs.com/panda-w/p/11374320.html