do the virtual mechanism works when virtual functions are called in
constructors?
Yes, but take care if you do!
The function called is the one in the class under construction, or one
of its base classes (12.7.3). If a function is pure virtual, it can't
be called unless it has been overridden.
Do Java and C# call the derived implementations of virtual functions
even though the derived part has yet not been constructed (its
constructor has not been called yet)?
>do the virtual mechanism works when virtual functions are called in
>constructors ?
>
Yes, but take care if you do!
Curiously, it's even possible to call base class functions *before*
the base class part of the object has been constructed at all, using a
small trick (which even more curiously is legal C++, although of course
extremely not recommended).
>
Do Java and C# call the derived implementations of virtual functions
even though the derived part has yet not been constructed (its
constructor has not been called yet)?
Do Java and C# call the derived implementations of virtual
functions even though the derived part has yet not been
constructed (its constructor has not been called yet)?
Don't know about C#, but Java does. It can easily be a source
of strange errors, too.
--
James Kanze (GABI Software) email:james.kan ze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
On May 28, 11:43 am, Juha Nieminen <nos...@thanks. invalidwrote:
Ian Collins wrote:
rajesh kalra wrote:
do the virtual mechanism works when virtual functions are called in
constructors?
>
Yes, but take care if you do!
>
Curiously, it's even possible to call base class functions *before*
the base class part of the object has been constructed at all, using a
small trick (which even more curiously is legal C++, although of course
extremely not recommended).
Can you post the trick (or refer to it)?
Just for the fun of it.
Thanks
Comment