基类中的赋值运算符似乎在派生类中不可用.鉴于此代码:
#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;
}
Run Code Online (Sandbox Code Playgroud)
GCC 6.4说:
错误:'operator ='不匹配(操作数类型为'B'和'int')
怎么了?