Serving the Quantitative Finance Community

 
User avatar
fradiavalo
Topic Author
Posts: 0
Joined: February 21st, 2006, 1:35 pm

virtual functions

April 20th, 2006, 12:58 pm

Can we call virtual functions in the ctor or dtor?If both base and derived classes provide impl of those virtual functions which version of the function will be called :- when an object of the base class is created?- when an object of the derived class is created?
 
User avatar
twofish
Posts: 0
Joined: February 18th, 2005, 6:51 pm

virtual functions

April 20th, 2006, 1:12 pm

1) You can but you shouldn't.2) It will call the base function in both cases, because the derived class has not been created or has already been destroyed and so there is no way for the system to call the derived function.Because of behavior 2, you get weird behavior.seehttp://www.artima.com/cppsource/nevercall.html