控制对象创建

Nav*_*een 1 c++ object

我有一个类,其对象必须在堆上创建.除此之外,还有更好的方法吗?

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();
};
Run Code Online (Sandbox Code Playgroud)