|
Boost Users : |
Subject: Re: [Boost-users] boost::exception_detail::error_info_base does not have virtual destructor
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2011-03-17 15:55:28
On Thu, Mar 17, 2011 at 12:27 PM, Ted Byers <r.ted.byers_at_[hidden]> wrote:
> 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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net