【发布时间】:2014-12-23 05:17:52
【问题描述】:
我希望基类中的方法调用将在派生类中实现的纯虚拟方法。但是,派生类似乎没有继承基类的无参数方法。我究竟做错了什么?编译器是 MSVC12。
错误 C2660: 'Derived::load' : 函数不接受 0 个参数
这是一个完整的示例(由于错误而无法编译):
struct Base
{
void load() { load(42); }; // Making this virtual doesn't matter.
virtual void load(int i) = 0;
};
struct Derived : Base
{
virtual void load(int i) {};
};
int main()
{
Derived d;
d.load(); // error C2660: 'Derived::load' : function does not take 0 arguments
}
【问题讨论】:
-
@Deduplicator 希望我可以为编辑 +1。
-
不客气,因为这只是最后的润色。
标签: c++ inheritance polymorphism overloading shadowing