C ++中的通用单例代码 [英] Generic singleton code in C++

查看:121
本文介绍了C ++中的通用单例代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



请告诉我一般单身人士的特色是什么?



是它是一个Singleton模板类?如果是,那么创建某个类的实例有什么困难,例如,类A {};使用那个通用单件模板?



问候



我尝试过:



i创建了一个通用的单例模板类,但在创建某个类的实例时遇到了困难。例如,A级{};使用该模板。

Hello All,

Please let me know what is speciality about generic singleton ?

Is it a Singleton template class ? if yes then what is the difficulty in creating an instance of some class, e.g., class A{}; using that generic singleton template ?

Regards

What I have tried:

i created a generic singleton template class but facing difficulty in creating an instance of some class. e.g., class A{}; using that template.

推荐答案

ok单件类是一个类,你可以只实例化一个对象的整体应用程序或服务,并有私人承包商

模板喜欢

ok singleton class is class that you can instantiated only one object overall application or service and has private contractor
template like
class Singleton
{
public:
static Singleton * getInstance()
{
  if(single==NULL)
{
  single = new Singleton();
}
return single;
}
private:
Singleton();
// some variable 
static Singleton * single;
} ;


这篇关于C ++中的通用单例代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆