#include<iostream>
using namespace std;
class Base
{
int x;
public:
Base(int a)
{
x = a;
cout<<"father constructing "<<x<<endl;
}
~Base()
{
cout<<"father destructing "<<x<<endl;
}
};
class Dervied:public Base
{
int y;
Base B2,B1;//只與定義順序有關
public:
Dervied(int a = 0,int b = 0,int c = 0,int d = 0):B1(d),Base(b),B2(c),y(a)//與參數列表的順序無關
{
cout<<"son constructing "<<y<<endl;
}
~Dervied()
{
cout<<"son destructing "<<y<<endl;
}
};
int main()
{
Dervied(1,2,3,4);
return 0;
}
[c++]容器類。繼承類的構造和析構
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.