#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;}
新闻热点
疑难解答