有这样的代码:#include类 Base {public: Base(){ std::cout << \'构造函数 base\' << std::endl; } ~Base(){ std::cout << \'
有这样的代码:
#include <iostream>
class Base {
public:
Base(){
std::cout << "Constructor base" << std::endl;
}
~Base(){
std::cout << "Destructor base" << std::endl;
}
Base& operator=(const Base& a){
std::cout << "Assignment base" << std::endl;
}
};
class Derived : public Base{
public:
};
int main ( int argc, char **argv ) {
Derived p;
Derived p2;
p2 = p;
return 0;
}
经过g++4.6编译后的输出:
Constructor base
Constructor base
Assignment base
Destructor base
Destructor base
为什么虽然说赋值运算符不能被继承,但却调用基类的赋值运算符呢?
赋值运算符继承
下载声明:
本站所有软件和资料均为软件作者提供或网友推荐发布而来,仅供学习和研究使用,不得用于任何商业用途。如本站不慎侵犯你的版权请联系我,我将及时处理,并撤下相关内容!