Boost logo

Boost Users :

From: Bobby Thomale (bthomale_at_[hidden])
Date: 2002-06-05 11:30:22


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/
---------------------------------------------------------------------


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