修改虚拟函数中的基类
Modify base class in virtual function
我有以下代码,在派生类的虚拟函数中,如何在基类中调用相同的函数以修改基类?
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+=(rhs);
致电基本版本。
相关文章:
- 虚拟基类函数中派生类的大小
- 无法访问基类函数 C++
- 如何使派生类函数在调用时始终调用相同的基类函数?
- C++虚拟函数:基类函数是调用的,而不是派生的
- Qt基类函数定义
- 添加字符串类型的类成员会导致调用基类函数而不是子函数
- 有没有办法调用基类函数,该函数在使用私有继承的派生类中被覆盖?
- C++ - 基类函数指针调用的替代方法
- 什么更有效率?在重载函数中或通过在基类函数中检查对象类型来实现
- 重载基类函数是不好的做法吗?
- 在 qml 中公开基类函数
- 调用基类函数时强制使用类名?
- 如何判断哪个派生的类对象称为基类函数
- 获取具有基类函数的派生类
- 有没有办法从基类函数参数中推断出模板参数
- 私有非虚拟基类函数被称为派生类中的函数
- 模板基类函数成员的别名
- 如何用相同的签名从main调用基类函数
- C++ 如何从 main 调用派生的基类函数
- memcpy派生类到基类,为什么还调用基类函数