Note that there are some explanatory texts on larger screens.

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

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload