Opened 20 years ago

Closed 15 years ago

#105 closed Feature Requests (wontfix)

Why noncopyable destructor isn't virtual — at Version 5

Reported by: wusan@… Owned by: nobody
Milestone: Component: None
Version: Boost 1.34.0 Severity: Cosmetic
Keywords: Cc:

Description (last modified by Dave Abrahams)

Rule 14 in "Effective C++ 2/e":
   "Make sure base classes have virtual destructors."

But why base class noncopyable doesn't have ?

Change History (5)

comment:1 by nobody, 18 years ago

Logged In: NO 

Does anybody want to have pointers of noncopyable?

comment:2 by rzymek, 17 years ago

Logged In: YES 
user_id=419557

This would be a problem if you used it like this:

class A : private boost::noncopyable  {
/* ... */
};

noncopyable* a = new A;
delete a;

But noncopyable isn't supposed to be used this way.

comment:3 by rzymek, 17 years ago

Logged In: YES 
user_id=419557

This would be a problem if you used it like this:

class A : private boost::noncopyable  {
/* ... */
};

noncopyable* a = new A;
delete a;

But noncopyable isn't supposed to be used this way.

comment:4 by nobody, 16 years ago

Logged In: NO 

one should not use the pointer to a noncopyable object

A tyical code should look something like this:

class A: private noncopyable
{
}

A* pa = new A();
delete pa;

And, the private will make sure that no one can access A
through noncopyable interface. 

So you cannot say:

noncopyable* pnc = new A();

it will create an error message like:

a.cxx: In function `int main()':
a.cxx:11: error: `noncopyable' is an inaccessible base of `A'

regards,

Sambit

comment:5 by Dave Abrahams, 15 years ago

Description: modified (diff)
Reporter: changed from wusan to wusan@…
Resolution: Nonewontfix
Severity: Cosmetic
Status: assignedclosed
Version: Nonerelease 1.34.0

The answer why not is that it would add needless overhead.

Note: See TracTickets for help on using tickets.