Boost logo

Boost Users :

From: Bobby Thomale (bthomale_at_[hidden])
Date: 2002-06-05 16:45:09


on 6/5/02 12:49 PM, Mark Storer at mstorer_at_[hidden] wrote:

> This is more of a C++ question than a boost one (which is why I can answer
> it;).

:-) Yep. Thanks!

> I'm guessing the author, Dave Abrahams, didn't think anyone was going to
> declare a noncopyable*, so decided to pass on that little bit of extra
> overhead involved in declaring a destructor virtual. Or it could be a
> mistake.

I am sure he meant to leave it non-virtual. There's more than just a little
calling overhead involved - there's also per-object space overhead. If it
was virtual, then any class derived from it would have a vtable, which is
often not what you want at all. By making it non-virtual, it gives the user
the choice of using it to create either a polymorphic or non-polymorphic
class, depending on your needs.

Furthermore, by making the destructor protected, I suspect that this would
cause any attempt to delete a noncopyable* to generate an error? Is that
right?

I just wanted to make sure that this would work the way I thought it did if
I start using it in my non-copyable base classes. (Mainly I was curious
about whether this would keep the noncopyable destructor from being called -
apparently the answer is no, which is good.)

It's very clever - I have seen other people encapsulate the boilerplate
non-copyable stuff in wacky macros and stuff before, but the noncopyable
base class is _much_ more elegant, and so simple!

                                -- Bobby

---------------------------------------------------------------------
Bobby Thomale
Senior Software Developer
Inoveon Corporation
http://www.inoveon.com/
---------------------------------------------------------------------


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