标签:include public mamicode base ret 运行 nbsp 初始 调用
源程序:
#include<iostream>
using namespace std;
class CBase
{
public:
CBase() {}
CBase(CBase &c)
{
cout << "CBase::复制构造函数" << endl;
}
CBase & operator=(const CBase & b)
{
cout << "CBase::operator=" << endl;
return *this;
}
};
class CDerived :public CBase
{
public:
CDerived()
{
cout << "CDerived::复制构造函数" << endl;
}
};
int main()
{
CDerived d1, d2;
CDerived d3(d1); //d3初始化过程中会调用类CBase的复制构造函数
d2 = d1; //会调用类CBase重载的“=”运算符
system("pause");
return 0;
}
运行结果:
标签:include public mamicode base ret 运行 nbsp 初始 调用
原文地址:https://www.cnblogs.com/duanqibo/p/12260300.html