Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::exception_detail::error_info_base does not have virtual destructor
From: Ted Byers (r.ted.byers_at_[hidden])
Date: 2011-03-17 14:17:57


Hi Stevem,

>-----Original Message-----
>From: boost-users-bounces_at_[hidden]
[mailto:boost-users-bounces_at_[hidden]] On Behalf Of Steven Watanabe
>Sent: March-17-11 12:37 PM
>To: boost-users_at_[hidden]
>Subject: Re: [Boost-users] boost::exception_detail::error_info_base does
not have virtual destructor
>
>AMDG
>
>On 03/17/2011 08:50 AM, Jens Auer wrote:
>> I am compiling a project with a more strict warning set and got the
following reports:
>> Error 29 error C4265:
'boost::exception_detail::error_info_base' : class has virtual functions,
but destructor is not virtual
c:\work\svn\sandbox\externals\boost\include\boost-1_45\boost\exception\detai
l\error_info_impl.hpp 36
>>
>> Error 30 error C4265: 'boost::error_info<Tag,T>' : class has
virtual functions, but destructor is not virtual
c:\work\svn\sandbox\externals\boost\include\boost-1_45\boost\exception\detai
l\error_info_impl.hpp 69
>>
>> IMHO these classes should have a virtual destructor as they are intended
to be used as base classes.
>
>No they shouldn't. A virtual destructor
>is only needed when deleting through
>a base class pointer. This is explicitly forbidden by making the destructor
protected.

I must respectfully disagree.

There are two ways to look at this 'should'. First, there is what is
required or permitted by the standard. Second, there is what is useful in
managing a software development project. When I am trying to help my
juniors develop good programming habits, one of the things I want them to do
is always provide a virtual destructor whenever they make one or more member
functions virtual. That lets a team comprised of many more junior
programmers than really really old guys like me avoid a lot of subtle bugs.
And I don't see a significant down side to making a destructor virtual.
Hence, when I am mentoring junior programmers, I routinely advise them to
make destructors virtual whenever they need one of the other member
functions to be virtual, whenever the issue arises.

Are you aware of a significant downside to making destructors virtual as a
matter of habit?

Cheers

Ted


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