This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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*) {} | |
}; |
No comments:
Post a Comment