10.6——單例模式案例

LoveAthene發表於2020-10-06
#define _CRT_SECURE_NO_WARNNING
#include<iostream>
using namespace std;
//建立主席類
//需求 單例模式 為了建立類中的物件,並且保證只有一個物件例項
class Chirman
{
	//1.建構函式進行私有化
private:
	Chairman() 
	{
		cout << "建立國家主席" << endl;
	}
public:
	satic Chairman* sinleMan;
};
Chairman* Chairman::singleMan = new Chairman;


void test01()
{
	/*Chairman c1;
	Chairman* c2 = new Chairman;
	Chairman* c2 = new Chairman;*/
	Chairman::singleMan;
}





int main()
{
	test01();
	system("pause");
	return EXIT_SUCCESS;
}

相關文章