#pragma once
template
class CSingleton
{
public:
static T * InstancePtr()
{
if( ms_Instance == NULL ) ms_Instance = new T;
return ms_Instance;
};
static T & Instance()
{
if(ms_Instance == NULL) ms_Instance = new T;
return *ms_Instance;
};
static void DestroyInstance()
{
delete ms_Instance;
ms_Instance = NULL;
};
private:
static T * ms_Instance;
};
template T* CSingleton::ms_Instance = 0;
#include "stdafx.h"
#include
#include "CSingleton.h"
class CObject : public CSingleton
{
public:
CObject() : m_nValue(10) {}
~CObject();
int m_nValue;
int GetValue() { return m_nValue; }
};
#define TIME CObject::Instance()
int _tmain(int argc, _TCHAR* argv[])
{
int time = TIME.GetTime();
return 0;
}
글 걸기 주소 : 이 글에는 트랙백을 보낼 수 없습니다
덧글을 달아 주세요