C++ 派生类的运算符重载
赋值运算符函数不是构造器,所以可以继承,语法上就没有构造器那么严格。
语法
子类& 子类::operator=(const 子类& another)
{
父类::operator =(another); // 调用父类的赋值运算符重载
...
}
赋值顺序
引例1:当子类,不自实现赋值运算符函数重载时,默认调用父类的赋值运算符函数
//todo 派生类运算符重载
#include <iostream>
using namespace std;
class A{
public:
int a;
A(){
cout << "A()" << endl;
}
A & operator=(const A& other){
this->a=other.a;
cout << " A & operator=(const A& other) " << en