[gameprogrammer] Re: Pure virtual function getting called

On Thu, May 20, 2004 at 12:27:51PM +1000, Dave Slutzkin wrote:

> Basically, it is generally legal to call virtual functions from the
> constructor or destructor, but the only version of the function you will
> get is the one in the current class.  This is because the compiler in
> general has no way of knowing whether the other classes are ready for the
> call.

More precisely, the compiler knows exactly that the derived class is
*not*, and cannot be, ready for the call.

Derived classes get constructed from ground up (base class constructor
is called first, most derived class constructor last) which makes sense
since derived classes' constructors can depend on base classes' data
members being valid.  Constructing the base class portion first is safe
since there's nothing the base class constructor could depend on.

So an otherwise virtual call made in constructor is not really virtual
since it might use not yet constructed portions of the instance.

        latimerius



---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: