Singleton
原创
©著作权归作者所有:来自51CTO博客作者JeaminThk的原创作品,请联系作者获取转载授权,否则将追究法律责任
Singleton 模式文件
// .h
//
#pragma once
#include <iostream>
using namespace std;
#define DECLEAR_SINGLE_INSTANCE(T) \
private:static T m_SingletonInstance; \
public:static T* Instance(){ return &m_SingletonInstance;}
#define IMPLEMENT_SINGLE_INSTANCE(T) \
T T::m_SingletonInstance;
class CSystemConfig
{
public:
CSystemConfig(){}
~CSystemConfig(){}
public:
DECLEAR_SINGLE_INSTANCE(CSystemConfig);
public:
void Initialize()
{
cout<<""<<endl;
cout<<""<<endl;
}
};
测试文件
#include "Singleton.h"
IMPLEMENT_SINGLE_INSTANCE(CSystemConfig) // 怎么解释这句话的功能呢?
void main()
{
CSystemConfig::Instance()->Initialize();
}