【发布时间】:2019-12-06 15:41:50
【问题描述】:
我正在尝试继承一个抽象类并覆盖它的所有纯虚函数
class A
{
virtual bool operator==(const A&) const = 0;
}
class B : A
{
bool operator==(const B& rhs) const override
{ ^^^^^^^^---problem here
// Comparison
}
}
错误:
运算符 'bool B::operator==(const B& rhs) const' 具有 'override' 说明符,但不覆盖基类成员
【问题讨论】:
-
如果你也有派生类C,你对
A&& a1 = B(); A&& a2 = C(); a1 == a2;有什么期望?访客模式可能有助于进行多次调度。
标签: c++ inheritance abstract-class