C++学习(16)
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 }
?
轉載于:https://www.cnblogs.com/Tobi/p/9249836.html
總結
- 上一篇: 关于数据精度的一些事
- 下一篇: C++编程基础二 03-const形参与