如何只在堆上创建对象,如何只在栈上创建对象
class HeapOnly
{
public:
HeapOnly() { cout << "constructor." << endl; }
void destroy () const { delete this; }
private:
~HeapOnly() {}
};
class OnlyStack
{
public:
OnlyStack(){}
private:
void* operator new( size_t );
};