单例模式全局仅一个实例,用于获取公共的内容
头文件mglobalinfomgr.h
- class MGlobalInfoMgr
- {
- MGlobalInfoMgr();
- ~MGlobalInfoMgr();
- public:
- static MGlobalInfoMgr* GetInstance();
- private:
- static MGlobalInfoMgr* _instance;
- };
源文件mglobalinfomgr.cpp
- MGlobalInfoMgr* MGlobalInfoMgr::_instance = NULL;
- MGlobalInfoMgr::MGlobalInfoMgr()
- {
- cout<<"new mgr";
- }
- MGlobalInfoMgr::~MGlobalInfoMgr()
- {
- //
- }
- MGlobalInfoMgr* MGlobalInfoMgr::GetInstance()
- {
- if(!_instance)
- {
- _instance = new MGlobalInfoMgr();
- }
- return _instance;
- }