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]

egcs-1.1 and virtual method questions


Hello everyone,

I have a question concerning egcs 1.1 and virtual methods. There
may be a bug in egcs but I need more background.

In a 20K+ pile of C++ code which I am supposed to maintain (I didn't
write the stuff), I have a problem with virtual methods not acting
as expected.

Given the base class:

class foo {
public:
     foo();
     ~foo();

     virtual bool do_something();
};

and the class:

class foobar : public foo {
public:
     foobar();
     ~ foobar();

     bool do_something();
};

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

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

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

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 !

Thanks for your help,
Gilles Depeyrot


Gilles Depeyrot                    <mailto:Gilles.Depeyrot@wanadoo.fr>
                             <http://perso.wanadoo.fr/gilles.depeyrot>



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