1 #include <iostream> 2 using namespace std; 3 4 //构造的时候,从父类到子类构造 5 //子类构造先调用父类构造 6 class myclass 7 { 8 public: 9 int x; 10 int y; 11 12 public: 13 myclass(int a,int b):x(a),y(b) 14 { 15 cout << "myclass" << endl; 16 } 17 ~myclass() 18 { 19 20 } 21 }; 22 23 class newmyclass :public myclass 24 { 25 public: 26 int z; 27 public: 28 newmyclass(int a, int b,int c) :myclass(a, b),z(c) 29 { 30 cout << "newmyclass" << endl; 31 } 32 33 }; 34 35 class newnewclass :public newmyclass 36 { 37 public: 38 int l; 39 public: 40 newnewclass(int a, int b, int c, int d) :newmyclass(a,b,c), l(d) 41 { 42 cout << "newnewclass" << endl; 43 } 44 }; 45 46 void main() 47 { 48 newnewclass my(1,2,3,4); 49 cin.get(); 50 }