Boost logo

Boost :

From: Saul Tamari (saul_tamari_at_[hidden])
Date: 2000-04-30 00:33:33


HI

I think that even though you declared the various new & delete operators to
be private, a user may still dynamicaly allocate an object of your class
using the global new.

bye
saul

> ----------
> From: Jeffrey D. Paquette
> Reply To: boost_at_[hidden]
> Sent: Saturday, April 29, 2000 3:06 PM
> To: boost_at_[hidden]
> Subject: [boost] Proposal: class nonallocatable
>
> I've been following this group for a few months now and have seen several
> variations of scoped utility classes fly by (shared_ptr, deferred_value,
> etc) and it seems that all of these classes, including a few that I've
> written have one drawback that can lead to misuse: they all can be
> dynamically allocated, thus bypassing the intent of the class.
>
> So, in the spirit of noncopyable, here is a first cut at nonallocatable:
>
> class nonallocatable {
> private:
> // single instance new and delete
> void *operator new(size_t);
> void operator delete(void *);
> void *operator new(size_t, const std::nothrow_t&) throw ();
> void operator delete(void *, const std::nothrow_t&) throw ();
> // array new and delete
> void *operator new[](size_t);
> void operator delete[](void *);
> void *operator new[](size_t, const std::nothrow_t&) throw ();
> void operator delete[](void *, const std::nothrow_t&) throw ();
> // placement new and delete
> void *operator new(size_t, void *) throw ();
> void operator delete(void *, void *) throw ();
> void *operator new[](size_t, void *) throw ();
> void operator delete[](void *, void *) throw ();
> };
>
> The idea is to derive scope-helper classes from nonallocatable, thus
> preventing the misuse of these classes, like so:
>
...


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