#include <iostream>
using namespace std;
class T
{
public:
int a;
virtual void SetA(const int _a)
{
a = _a;
}
virtual void Print(const int _b)
{
cout << "Virtual Print Fuction!" << endl;
}
static T* GetInstance()
{
T *pInstance = new T();
return pInstance;
}
static void DestroyInstance(T* pInst)
{
if(pInst)
{
delete pInst;
pInst = NULL;
}
}
private:
T(){cout << "T() is called" << endl;}
~T(){cout << "~T() is called!" << endl;}
void func(int n) {cout << "ddddd" << endl;}
public:
void Test(){func(100);}
};
int main()
{
T* Inst = NULL;
Inst = T::GetInstance();
T::DestroyInstance(Inst);
return 1;
}
单例模式c++例子
最新推荐文章于 2024-06-23 22:55:37 发布