码迷,mamicode.com
首页 > 编程语言 > 详细

[c++]容器类。继承类的构造和析构

时间:2015-04-09 19:58:44      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:c++      继承   

#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++]容器类。继承类的构造和析构

标签:c++      继承   

原文地址:http://blog.csdn.net/cherry_ermao/article/details/44963039

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!