I am confused by compiler errors regarding the code below:
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); }
Using gcc 4.6.3, the above code throws an error in d.func (0) saying that Dervied :: func (int) is undefined.
When I also add a definition for func (int) in Derived, then it works. It also works (as in the case of the “other”) when I do not define either func () or func (int) in Derived.
It’s clear that there is some rule regarding virtual overloaded functions, but this is the first time I came across this, and I don’t quite understand it. Can someone tell me what exactly is going on here?
source share