Boost logo

Boost Users :

From: Mark Storer (mstorer_at_[hidden])
Date: 2002-06-05 12:49:57


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

Your deletes are fine. The only way this would cause a problem is to delete
through a boost::noncopyable pointer (in which case everything derived from
it would leak).

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.

Dave has posted to this list at least once... So tell us, did you mean to
leave it non-virtual?

--Mark Storer
  Software Engineer
  Cardiff Software

#include <disclaimer>
typedef std::disclaimer<Cardiff> Discard;

-----Original Message-----
From: Bobby Thomale [mailto:bthomale_at_[hidden]]
Sent: Wednesday, June 05, 2002 9:30 AM
To: Boost Users List
Subject: [Boost-Users] boost::noncopyable usage question

I have a simple question about the usage of boost::noncopyable. I think I
know the answer, but I am not sure.

The noncopyable class defines a non-virtual destructor. Generally speaking,
overriding a non-virtual destructor is considered a "bad thing" but in
certain cases (like, I am guessing, this one) it is okay and works like
you'd expect.

Here's what I am worried about:

Let's say I have a base class of an inheritance tree that I want to be
non-copyable. So I do this:

class MyBase : private boost::noncopyable {
    public:
        MyBase ();
        virtual ~MyBase ();
    
        ...
};

Then I derive from it class A:

class A : public MyBase {
    public:
        A ();
        virtual ~A();
};

and define a destructor for class A, too.

Does this do what I would expect, ie whether I delete a MyBase* or an A*, it
calls the destructors for both A and MyBase like it is supposed to?

I suppose the trivial, empty noncopyable destructor never gets called (which
is okay) whether I delete a MyBase* or an A*, correct? (Just curious...)

                                -- Bobby

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

Info: <http://www.boost.org>
Wiki: <http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl>
Unsubscribe: <mailto:boost-users-unsubscribe_at_[hidden]>
 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/


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