单例模式

#define _CRT_SECURE_NO_WARNINGS
#include 
using namespace std;
#include 

class singleman
{
public:
	static singleman* getInstance()
	{
		return sman;
	}
private:
	singleman()
	{
		cout << "jkd" << endl;
	}
	singleman(const singleman& c){};
private:
	static singleman * sman;


};

singleman * singleman::sman = new singleman;

void test()
{
	singleman * oneman = singleman::getInstance();
	singleman * twoman = singleman::getInstance();
	if (oneman == twoman)
	{
		cout << "yiyang" << endl;
	}

	//singleman * threeman = new singleman(*twoman);
	/*
	if (threeman == twoman)
	{
		cout << "yiyang" << endl;
	}
	else
	{
		cout << "budeng" << endl;
	}
	*/
}

int main()
{	

	test();

	system("pause");
}

 

你可能感兴趣的:(c/c++)