十一 29


#include
using namespace std;

template
class CSingleton {
public:
static T* instance();
static T _instance;
};

template
T CSingleton:: _instance;

template
T* CSingleton:: instance()
{
return &_instance;
}

class CTest
{
public:
CTest()
{
cout << "Construct" << endl;
};
~CTest()
{
cout << "Destruct" << endl;
};
};

typedef CSingleton CSingleTest;

void test()
{
CSingleTest::instance();
}

int main()
{
cout << "Begin of main" << endl;
cout << "End of main" << endl;
return 0;
}

What’s the output?

Leave a Reply

preload preload preload

无觅相关文章插件,快速提升流量