[prev in list] [next in list] [prev in thread] [next in thread]
List: boost
Subject: Re: [boost] [1.34.0beta] many, many warnings... :(
From: Jeff Garland <jeff () crystalclearsoftware ! com>
Date: 2007-05-05 18:10:12
Message-ID: 463CC884.6030209 () crystalclearsoftware ! com
[Download RAW message or body]
JOAQUIN LOPEZ MU?Z wrote:
>> I find inheriting without virtual functions quite useful. The
>> main reason for the virtual destructor rule goes back to Scott
>> Meyers Effective C++. He points out that if you have
>> Base <-- Derived and you call delete Base* the destructor of
>> Derived is not called. In general, it's hard to ensure your
>> derived classes won't need the destructor called and hence the
>> rule.
>> However, if Derived happens to have a trivial/empty destructor
>> then, really there's no reason to call it.
>
> I agree and disagree with your previous exposition :)
That's usual ;-)
> I think deriving without virtual constructors is fine in those
> contexts when the user is not expected to delete passed
> objects, which are by far the most usual. Almost every
> function of the form
>
> void foo([const] T& t)
>
> won't certainly try to delete t, so it's fine to pass an
> use here an object of some class derived from T (like in
> your super_string case.)
Sure, but in the general case you could easily create an interface like this:
void foo(T* t)
hence Scott's design rule.
>...snip...
>
> What I don't agree with you in is your claim that
> "if Derived happens to have a trivial/empty destructor
> then, really there's no reason to call it." If my
> memory serves me well, deleting a Derived object through
> its Base non-virtual dtor is illegal according to the
> standard, regardless of whether D's dtor is trivial or
> not. You're merely being lucky with the actual behavior
> exhibited by compilers.
By the standard I believe it is technically undefined behavior. But as a
practical matter it's defined exactly the same on all compilers -- call the
base class destructor.
Jeff
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic