问题遇到的现象和发生背景
如何在子类中重写父类的重载运算符+函数?
其中父类是个抽象类,它的重载运算符+函数是个纯虚函数。
问题相关代码,请勿粘贴截图
class Father
{
public:
virtual Father* operator+(Father*) = 0;
};
class Son:public Father
{
public:
Son(int a, int b) {
this->a= new int(a);
this->b= new int(b);
}
Father* operator+(Father* other) {
//此处如何书写?
}
private:
int *a= nullptr;
int *b= nullptr;
};
int main() {
Father* son1 = new Son(1, 2);//图形1
Father* son2 = new Son(3, 4);//图形2
auto son3=son1+
son2 ; //报错,无法实现
}