继承与构造函数与析构函数

#include<iostream>
using namespace std;
class father
{
public:
    father()
    {
        cout << "father无参构造函数" << endl;
    }
    father(int x):fa(x)
    {
        cout << "father单参构造函数" << endl;
    }
    ~father() 
    {
        cout << "father析构函数" << endl;
    }
    int fa;
protected:
    int fb;
private:
    int fc;
};
class son:public father
{
public:
    son(int x):sa(x)
    {
        cout << "son单参构造函数" << endl;
    }
    ~son()
    {
        cout << "son析构函数" << endl;
    }
    int sa;
protected:
    int sb;
private:
    int sc;
};
int main()
{
    son s1(0);
}

二,

1,若在设计程序时,基类和派生类均未设计拷贝构造函数,C++编译器将自动产生按位拷贝的拷贝构造函数     //   0   0

2,若基类有拷贝函数,派生类没有函数,将在派生类中生成按位拷贝的拷贝构造函数    //   1   0

3,若在基类和派生类均设计了拷贝函数,在派生类中没有指明基类构造函数类型时,使用缺省的拷贝函数,若没有缺省函数,编译错误     //   1    1

4,若在基类未设计拷贝构造函数,派生类设计了,在派生类中没有指明基类构造函数类型时,使用缺省的拷贝函数,若没有缺省函数,编译错误    //    0  1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值