#define _CRT_SECURE_NO_WARNINGS#include <iostream>using namespace std;class Instance{PRivate: Instance(){} /*私有化復制構造函數*/ Instance(const Instance&){} /*私有化=操作符*/ Instance& Operator=(const Instance&){}public: static Instance *getInstance() { return Singleton; }public: static Instance *Singleton;};/*初始化*/Instance *Instance::Singleton = new Instance;/*測試*/void test(){ Instance *p1 = Instance::getInstance(); Instance *p2 = Instance::getInstance(); if (p1 == p2) { cout << "p1 = p2" << endl; } else { cout << "p1 != p2" << endl; }}int main() { test(); system("pause"); return EXIT_SUCCESS;}
新聞熱點
疑難解答