egcs-1.1 and virtual method questions

Gilles Depeyrot Gilles.Depeyrot@wanadoo.fr
Wed Nov 18 17:05:00 GMT 1998


Le (the) 18/11/98 23:38, Mike Stump a écrit (wrote) :

>> 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.
>
>You don't give an testcase, we can't help you easily without it.

Well I may try to extract a test case but as a wrote, the code is poorly
written and very compact and I am trying to correct bugs and enhance
maintainability.

>> 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();
>> };

[snip]

>And without and detail, we can't help.  Here are the possibilities:
>
>    1)  You called it non-virtually  (foo::do_something()),

Nope, it is called with object->do_something()

>    2)  The object's type is in fact foo, you just are confused and thing
>	it is foobar,

Nope, that's the first thing I checked using the debugger (gdb) and the
virtual table is that of foobar.

>    3)  A compiler bug slicing when it shouldn't (unlikely),
>    4)  Vtable filling problem (unlikely).

I *know* its unlikely. I'm trying to understand what is going on and I am
not a novice in C++ programming, that's why I'm writing to this list.

Thanks for your help,
Gilles Depeyrot

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




More information about the Gcc-bugs mailing list