virtual inheritance problem
Wolfgang Bangerth
wolf@gaia.IWR.Uni-Heidelberg.De
Wed Mar 10 04:32:00 GMT 1999
Ryszard Kabatek <rysio@rumcajs.chemie.uni-halle.de>
Wed, 10 Mar 1999 10:42:23 +0100 (CET) writes:
>Egcs-1.1.1 produces wrong code:
>
>starting test
>A::foo 0xbffff8d8 1
>B::foo 0xbffff8d0 1073783640 <-- should be 1
>C::foo 0xbffff8d0 1073783640 <-- should be 1
>D::foo 0xbffff8c4 1073783640 <-- should be 1
>E::foo 0xbffff8c0 1
>object constructed
>E::foo 0xbffff8c0 1
>test finished
You are calling virtual functions from the constructor, i.e. at a time
where derived classes may not have been able to
1/ set their virtual function's addresses in the virtual function table
(this is why you get to see the output of the functions [ABCD]::foo,
which later will not be called anymore since E::foo is there); and
2/ set their member variables' values, since base classes are always
constructed first.
The program is therefore bound to produce rather random output.
Regards
Wolfgang
-------------------------------------------------------------------------
Wolfgang Bangerth email: wolf@gaia.iwr.uni-heidelberg.de
www: http://gaia.iwr.uni-heidelberg.de/~wolf
More information about the Gcc
mailing list