单例模式

自己尝试去不用指针的方式写,但是好像发现类不能作为参数,而且也没找到能不能判断类是否存在的函数,所以还是用了指针!

#include "stdafx.h"

class CSingle{

public:
	static CSingle* InstanceOf(){
		if(theSingle == NULL){
			theSingle = new CSingle();
		}
		return theSingle;
	}
private:
	static CSingle* theSingle;
	CSingle(){};
	
};

CSingle* CSingle::theSingle = NULL;


int main(int argc, char* argv[])
{
	CSingle* s = CSingle::InstanceOf();
	return 0;

}


posted @ 2020-02-24 01:24  zpchcbd  阅读(126)  评论(0)    收藏  举报