64,654
社区成员
发帖
与我相关
我的任务
分享
#pragma once
template <class T>
class Singleton
{
public:
typedef SingleTon<T> Myself;
static MySelf* GetInstance(){
if(instance_ == NULL){
instance_ = new MySelf();
}
return instance_;
}
private:
static MySelf* instance_;
}
template <class T>
SingleTon<T>* SingleTon<T>::instance_ = NULL;
typedef SingleTon<int> IntSingleTon;
//test.h
#ifdef TEST_EXPORTS
#define TEST_API __declspec(dllexport)
#else
#define TEST_API __declspec(dllimport)
#endif
TEST_API void PrintTest();
#include "test.h"
#include <stdio.h>
#include "a.h"
TEST_API void PrintTest()
{
printf("IntSington Addr: %p\r\n", IntSingleTon::GetInstance() );
}
#include <stdio.h>
#include "test.h"
int main()
{
PrintTest();
printf("In Exe IntSingleTon Addr:%p\r\n", IntSingleTon::GetInstance() );
return 0;
}