This is the mail archive of the gcc-bugs@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]

Re: egcs-1.1 and virtual method questions


> You can notice that the virtual method of class foo is overridden in
> class foobar but is *not* declared as virtual.

Doesn't matter, you only need to declare it virtual in the base.

> If I manipulate objects of class foobar with a foo pointer, which method
> should be called for do_something ?

The function of the derived class.

> Shouldn't the compiler emit a warning because do_something is overridden
> but not declared virtual ?

No, this is valid C++, and frequently used.

> In my code, with an object of class foobar manipulated with a foo pointer,
> the do_something method which is effectively called is foo's do_something
> instead of foobar's do_something !

That would depend on the code. For example, if you do the virtual call
in a constructor, things are different. Also, if you create a foo object
before calling the method, you get foo::do_something.

If it is neither of these, report it as a bug.

Regards,
Martin


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