【发布时间】:2021-07-31 06:14:20
【问题描述】:
基类中的赋值运算符在派生类中似乎不可用。鉴于此代码:
#include <iostream>
class A{
int value;
public:
A& operator=(int value){
this->value = value;
return *this;
}
};
class B : public A{};
int main(){
B b;
b = 0; // Does not work
return 0;
}
GCC 6.4 说:
错误:'operator=' 不匹配(操作数类型为 'B' 和 'int')
发生了什么?
【问题讨论】:
标签: c++ inheritance assignment-operator