标签:++ clu code div com cte public ima 派生类
1 //基类和派生类的析构函数 2 #include<iostream.h> 3 class A{ 4 protected: 5 int a1; 6 float a2; 7 public: 8 A(int x1=0,float x2=0){ 9 a1=x1; 10 a2=x2; 11 } 12 A(A &a){ 13 a1=a.a1; 14 a2=a.a2; 15 } 16 ~A(){ 17 cout<<"类A的析构函数调用"<<endl; 18 } 19 }; 20 21 class B:public A{ 22 private: 23 int b1; 24 float b2; 25 public: 26 B(int x1=0,float x2=0,int y1=0,float y2=0):A(x1,x2){ 27 b1=y1; 28 b2=y2; 29 } 30 B(B &b):A(b.a1,b.a2){ 31 b1=b.b1; 32 b2=b.b2; 33 } 34 ~B(){ 35 cout<<"类B的析构函数调用"<<endl; 36 } 37 }; 38 int main(){ 39 B myB; 40 B myOtherB(myB); 41 return 0; 42 }
标签:++ clu code div com cte public ima 派生类
原文地址:https://www.cnblogs.com/Tobi/p/9249836.html