Noah Roberts wrote:
>
> On Jan 25, 7:30 am, Michael DOUBEZ <michael.dou...@free.fr> wrote:
>> Thomas Kowalski a écrit :
>
>>> guess the only way is to have something like a protected init method
>>> that should be called in the constructor??
>> Yes. But from 10.3/6 of the standard this is undefined.
>> The reason is that when the virtual function is called, the derived
>> object doesn't already exists and cannot use member data.
>
> The yes is a bit misleading though. It never works right. IMO
> anything undefined is considered, "no, you can't do that," especially
> when the usual result is anything but what you think you want.
>
But the "It never works right" is also a bit misleading <g>, since the
effect of calling a virtual function from a constructor is well defined,
unless the function is pure virtual. On the other hand, it won't solve
the original problem, because the function belonging to the base
currently being constructed is called, and not the function belonging to
the derived class.
--
-- Pete
Roundhouse Consulting, Ltd. (
www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (
www.petebecker.com/tr1book)