Why can we have a virtual destructor but not virtual开发者_Go百科 constructor?
The constructor chain can be determined at compile time, because you use new ClassName()
always from the most specific class possible.
However you call destructors on possibly parent classes if you use polymorphism, so you can't know at compile time where to start the chain from. You need a virtual function to always call the right one (or you'd end up with potentially uncleaned resources in the most specific classes).
精彩评论