Boost logo

Boost :

From: Jonathan Franklin (franklin.jonathan_at_[hidden])
Date: 2007-05-05 16:05:30


On 5/5/07, Jeff Garland <jeff_at_[hidden]> wrote:
>
> Jonathan Franklin wrote:
>
> > For example, GCC has a
> >> warning about a derived class whose base doesn't have a virtual dtor.
> >> It's actually *impossible* (not just inefficient or convoluted) to
> >> implement is_polymorphic without generating that warning.
> >
> >
> > Interesting. I'm obviously flaunting my ignorance, but I didn't realize
> > that inheriting from a class sans virtual dtor was ever a Good
> Thing. I'll
> > have to read up on the issues WRT is_polymorphic.

Sorry, I slightly misspoke. What I meant to type was that I didn't realize
that inheriting from a class with virtual methods sans virtual dtor was ever
a Good Thing.

AFAICT gcc will only gripe if the base class defines virtual methods but no
virtual dtor. Perhaps this isn't the case with older versions of the
compiler.

I still need to read up on the issues WRT is_polymorphic, since they
obviously exist given David's previous statements.

I find inheriting without virtual functions quite useful.

I agree wholeheartedly.

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.

True. The first case *usually* (but not always) trumps the second, for the
reason that you mentioned, and additionally, just because when you wrote the
derived class with an empty/trivial dtor doesn't mean that someone else
won't add something non-trivial later and forget to add 'virtual' to the
base class dtor.

Jon


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk