单例的写法

来源:互联网 发布:linux 查询arp表 编辑:程序博客网 时间:2024/05/16 08:25

.h中

public:

   static Planes * getInstance();

protected:

   static Planes * instance;


.cpp

在函数外面要初始化静态成员变量。

Planes *Planes::instance = nullptr;

Planes *Planes::getInstance(){

   if (!instance) {

       instance = newPlanes();

    }

    returninstance;

}


0 0