You can not call virtual functions from constructor.
Such behavior is undefined - your class instance is not constructed yet.
Regards,
Alex
You can not call virtual functions from constructor.
Such behavior is undefined - your class instance is not constructed yet.
Regards,
Alex
@Alex, it is not undefined behavior, only the "overriding" doesn't work.
Overriding works only after the whole object is created because the objects are created from base class "down" - the base c-tor can't call a method in derived class since that slice of the object isn't created yet (or more correctly it's not yet initialized), so from c-tors and d-tor it's always the member function from the same class that gets called - so don't expect overriding.
^NyAw^ (21st November 2011)
Bookmarks