Boost logo

Boost :

From: Marshall Clow (marshall_at_[hidden])
Date: 2000-08-21 19:05:02


At 7:44 PM -0400 8/21/00, Daryle Walker wrote:
>Should we have a "nonnewable" class? It is similar to noncopyable, but it
>bans new and delete instead. Here's a quick mock-up:

Didn't Scott Meyers talk about this?
<flip, flip, flip, aha! More Effective C++, item #27>

>//==========================================================================
>namespace boost
>{
> //...
>
> class nonnewable
> {
> protected:
> nonnewable() {}
> ~nonnewable() {} // should this be virtual?
>
> private:
> void * operator new( std::size_t );
> void operator delete( void *, std::size_t );
> void * operator new[]( std::size_t );
> void operator delete[]( void *, std::size_t );
> };
>
> //...
>}
>//==========================================================================
>
>Would this prevent someone from creating an object of this class
>dynamically?

There's also "placement new", which this doesn't prevent.
     void* operator new ( std::size_t, void* ptr );

Other than that, it should work fine.

-- 
-- Marshall
"The era of big government is over."
           Bill Clinton, State of the Union Address, January 23, 1996
Marshall Clow     MusicMatch   <mailto:mclow_at_[hidden]>

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