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;
}
};
これは意味があります。しかし、なぜ 'Base'に' + = 'という関数がないので、なぜ' operator'という言葉を省略してBase :: + = rhs.Base; – Allanqunzi
@Allanqunziと書くことができないのだろうか? '*(static_cast (this))+ = rhs;'と書くことができますが、それは良いとは思いません:) –
mpiatek
@Allanqunzi演算子の構文はそのようには機能しません –