我有一個類,其對象必須在堆上創建。除此之外是否還有其他更好的方法:控制對象創建
class A
{
public:
static A* createInstance(); //Allocate using new and return
static void deleteInstance(A*); //Free the memory using delete
private:
//Constructor and destructor are private so that the object can not be created on stack
A();
~A();
};