Make your operator new private.
#include <new> struct Foo { int x; private: void* operator new (std::size_t size) throw (std::bad_alloc); };
In C ++ 0x, you can delete operator new :
struct Foo { int x; void* operator new (std::size_t size) throw (std::bad_alloc) = delete; };
Note that you need to do the same for the new[] operator separately.
source share