0
我有以下代码,在派生类的虚拟功能的虚拟功能,如何可以调用相同的功能在基类来修改基类?修改基类中
class Base{
public:
int a;
virtual Base & operator +=(Base const & rhs)
{
a += rhs.a;
return *this;
}
};
class Derived: public Base{
public:
int b;
virtual Derived & operator +=(Derived const & rhs)
{
// What should I write to invoke the += in Base class?
// something like Base::+=(rhs.Base);
b += rhs.b;
return *this;
}
};
这是有道理的。但我不知道为什么我不能省略字'operator'写'基地:: + = rhs.Base;' – Allanqunzi
@Allanqunzi也许是因为'Base'没有所谓'+ ='功能?你可以写'*(的static_cast (本))+ = RHS;'但我不认为这是更好:) –
mpiatek
@Allanqunzi运算符的语法不工作的方式 –