This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Question about -fall-virtual



Have I misunderstood the -fall-virtual switch purpose?

I thought that it would do:
  treat every member function as virtual, even if they are not
  prefixed by "virtual". 

However the following simple code:
#include<iostream.h>

struct A
{
    int hi () { return 0; }
};

struct B : public A
{
    int hi () { return 4; }
};

int main ()
{ 
    A *a = new B;

    cout << a->hi () << endl;
}

Compiled with -fall-virtual (egcs1.0.3) still prints the answer 0.
When I do as I should do according to the standard (that is prefix A::hi with
virtual), it prints 4 like it should.

I just want to get rid of the virtual prefix since all my classes are
virtual and -fall-virtual seemed like a good idea. :-)

What am I doing wrong? Any help greatly appreciated.

//Fredrik




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]