#define _CRT_SECURE_NO_WARNINGS#include <iostream>using namespace std;class Instance{PRivate: Instance(){} /*私有化復(fù)制構(gòu)造函數(shù)*/ Instance(const Instance&){} /*私有化=操作符*/ Instance& Operator=(const Instance&){}public: static Instance *getInstance() { return Singleton; }public: static Instance *Singleton;};/*初始化*/Instance *Instance::Singleton = new Instance;/*測(cè)試*/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;}
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注