B
BigMan
Is it safe to call nonvirtual member functions from ctors and dtors?
What about virtual ones?
What about virtual ones?
Is it safe to call nonvirtual member functions from ctors and dtors?
What about virtual ones?
With the exception of virtual calls to pure virtual functions in the constructorsPete said:Yes, it's safe. Unlike Java, C++ has a safe rule for virtual functions:
when a constructor or destructor calls a virtual function it calls the
function defined for the type whose constructor or destructor is
currently being run, which isn't necessarily the most derived type.
Ron Natalie said:With the exception of virtual calls to pure virtual functions in the
constructors
(these are undefined).
Ron said:With the exception of virtual calls to pure virtual functions in the constructors
(these are undefined).
That is the intended meaning and it is what the standard says.Peter said:Hi Ron
This is a slight surprise to me as i read it that pure virtual functions can
be called in destructors. Was that the intended meaning and if so - what is
the result?
Ron said:With the exception of virtual calls to pure virtual functions in the
constructors
(these are undefined).
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.