4
我感到困惑关于下面的代码编译器错误:困惑虚拟重载函数
class Base {
public:
virtual ~Base() { }
virtual void func() { }
virtual void func (int) { }
virtual void another() { }
virtual void another (int) { }
};
class Derived : public Base {
public:
void func() { }
};
int main() {
Derived d;
d.func();
d.func(0);
d.another();
d.another(0);
}
使用gcc 4.6.3,上面的代码导致在d.func(0)说Dervied ::错误func(int)未定义。
当我还将func(int)的定义添加到Derived时,它就可以工作。当我在Derived中既不定义func()也不func(int)时,它也起作用(就像“另一个”的情况一样)。
很明显,有一些规则有关虚拟重载函数会在这里,但是这是我第一次遇到它,我不太明白。有人能告诉我究竟发生了什么吗?
嘿感谢! !关于-Woverloaded的提示虚拟和修复功能非常有用;我甚至不知道我有过的问题的绝佳答案。 :-) – 2013-05-12 07:34:51