Thursday, 8 October 2009

Preventing creation of the objects on the stack/heap

Preventing creation of the objects on the stack:
class HeapOnly
{
public:
void destructor() { delete this; }
private:
~HeapOnly();
};
Preventing creation of the objects on the heap:
class AutoOnly
{
public:
private:
void* operator new(size_t) {}
void* operator new[](size_t) {}
void operator delete(void*) {}
void operator delete[](void*) {}
};
view raw gistfile1.cpp hosted with ❤ by GitHub

No comments:

Post a Comment