首页 > 编程语言 > 详细

C++ Singleton

时间:2014-09-28 02:33:11      阅读:276      评论:0      收藏:0      [点我收藏+]

Singleton in C++:

#include <iostream>
using namespace std;

class Restaurant {
public:
	static Restaurant *getInstance() {
		if (instance == NULL) instance = new Restaurant(100);
		return instance;
	}
	int getSize() { return size; }
	void setSize(int _size) { size = _size; }

private:
	Restaurant(int _size) { size = _size; }
	int size;
	static Restaurant *instance;
};

Restaurant *Restaurant::instance = NULL;

int main() {
	cout<<Restaurant::getInstance()->getSize();
	return 0;
}


C++ Singleton

原文:http://blog.csdn.net/jsc0218/article/details/39628537

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!