C ++-Singleton类 [英] C++-Singleton class

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

问题描述

可以继承单例类.如是,那我们该怎么办呢?

Can a singleton class be inherited. if yes, then how can we do it?

*****我的意思是说,如果我们有一个使用单例设计模式的类,那么它可以被继承吗?*

*****I mean to say that if we have a class which uses singleton design pattern,then can it be inherited?*

推荐答案

singleton具有私有构造函数,因此无法进行继承.除了singleton之外,还有静态方法来实例化私有实例成员,并且由于您无法覆盖静态方法,因此从singleton继承是毫无意义的.

singleton has private constructor so inheritance is not possible. besides singleton has static methods to instantiate private instance member and since you can't override static methods it would be pointless to inherit from singleton.

这篇关于C ++-Singleton类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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