5,531
社区成员
发帖
与我相关
我的任务
分享
template <typename T>
class Singleton
{
public:
static T* instance()
{
static T t;
return &t;
}
};
2 在dll A 模板实例化
//某cpp中
int * get() { return Singleton<int>::instance(); }
3.在 dll B 中实例化
int* retrieve(){ return Singleton<int>::instance(); }
4. 在main中,
int * p = get(); //from dll A
int * pp = retrive(); //from dll B
//这两个地址将不同
解决办法:
仅在其中一个dll A 中实例化模板,其他dll/exe直接使用 dll A。