单例模式(写LOG,读写配置文件等) c++
/* good old meyers' singleton */
template<class T>
class CSingleton
{
public:
static T& Instance()
{
static T theSingleton;
return theSingleton;
}
/* more (non-static) functions here */
private:
CSingleton();
CSingleton(CSingleton const&);
CSingleton& operator=(CSingleton const&);
~CSingleton();
};
使用时
CSingleton<CLOG>::Instance().LOG->info("This is log");