Compiler error when overwriting virtual methods
- by Stefan Hubert
Using VC71 compiler and get compiler errors, that i don't understand.
Here comes the example
class A
{
public:
virtual int& myMethod() = 0;
virtual const int& myMethod()const = 0;
};
class B: public A
{
public:
// generates: error C3241: 'const int &B::myMethod(void)' : this method was not introduced by 'A' virtual const int& A::myMethod() const;
virtual int& A::myMethod();
};
when i switch order of both method definitions in B then I see a different compiler error:
class B: public A
{
public:
virtual const int& A::myMethod() const;
// error C2556: 'const int &B::myMethod(void)' : overloaded function differs only by return type from 'int &B::myMethod(void)'
// error C2373: 'B::myMethod' : redefinition; different type modifiers
virtual int& A::myMethod();
};
however, if I omit the A:: stuff then i don't get any compiler error:
class B: public A
{
public:
virtual int& myMethod();
virtual const int& myMethod() const;
};
So, what exactly does A:: in front of my method names and why do i see these diverse compiler errors? Any explanation welcome!