
On Thu, Mar 17, 2011 at 12:27 PM, Ted Byers
Because I tend to let junior programmeers work only on those classes that would have a public destructor anyway. I find young, inexperienced programmers need to develop a good grounding on, or experience with, generally applicable patterns before being introduced to situations where one can usefully deviate from those patterns. <snip> Again, can you point to a significant downside to having all destructors virtual?
Virtual isn't something that you slap on functions for good measure; it is an invitation to call a function through a base pointer. I agree that it is best to teach basic patterns to novices. You could teach them to always make destructors in base types protected and non-virtual, and to use shared_ptr to manage the lifetime of (polymorphic) objects. From a different point of view, this simply means that delete (and the public virtual destructors it requires) is best treated as an advanced feature novices should avoid. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode