草庐IT

concrete-inheritance

全部标签

c++ - "Inheriting"具有可变模板函数的类

我想编写一个可以操作不同类型数据库(例如sqlite、postgres等)的数据库包装器,因此无论用户实际使用什么数据库,他们编写的代码都不会改变。在我看来,这需要一个抽象基类,例如:classdatabase{public:virtualboolquery(conststd::string&q)=0;//Otherstuff};classsqlite:publicdatabase{public:boolquery(conststd::string&q){//Implementation}};这看起来不错,但我正在使用可变参数模板来转义查询中的参数(我真的很喜欢这个想法,所以我想坚持下

c++ - 转发声明 : templates and inheritance

在编写框架时遇到以下问题:我有classA和classB派生自classA。classA有一个返回B*的函数。当然,这并不难:#includeusingnamespacestd;classB;//forwarddeclarationclassA{public:B*ReturnSomeData();};classB:publicA{};//Implementation:B*A::ReturnSomeData(){returnnewB;//doesn'tmatterhowthefunctionmakespointer}intmain(){Asth;cout但是我不得不使用像这里这样的模板:

c# - 如何在 C# 中使用 Private Inheritance aka C++ 以及为什么它不存在于 C# 中

我知道C++支持私有(private)继承,C#只支持公有继承。我还看到一篇文章说私有(private)继承通常定义类之间的HAS-A关系和某种聚合关系。编辑:私有(private)继承的C++代码:“Carhas-aEngine”关系也可以用私有(private)继承来表达:classEngine{public:Engine(intnumCylinders);voidstart();//StartsthisEngine};classCar:privateEngine{//Carhas-aEnginepublic:Car():Engine(8){}//InitializesthisCa

c++、cscope、ctags 和 vim : Finding classes that inherit from this one

在具有几层的相当大的代码库中,有没有办法在vim或命令行中找到从基类派生的所有类?grep是一个选项,但可能会很慢,因为grep没有索引。 最佳答案 cscope和ctags都不允许我们直接处理继承,但是相对解决这个限制是很容易的,因为派生类也被索引了。控制范围在cscope中,寻找“C符号”Foobar通常会列出原始类和继承自它的类。由于搜索是针对数据库完成的,因此速度快如闪电。或者,您可以使用cscope的egrep搜索功能和类似:.*Foobar的模式来列出仅继承自Foobar的类。因此,即使我们没有专门的“查找继承自此类的类

C++ : union of two types without virtual base class inheritance

是否可以在不手动创建交集类型的情况下创建两种类型的并集?问题是在我的上下文中交集类是完全没有意义的,所以创建它会使代码用户感到困惑。我的实际案例:我正在描述一个数字硬件模拟器,它是许多模块的分层树状结构:classport;classmodule0{porta,b,c;}classmodule1{portc,d,e;}我需要创建这两种类型的union:classtop_level_module{porta,b,c,d,e;}我想应该有一些技术来创建union类型(这是我要问的问题):classtop_level_module:union_type{//porta,b,c,d,e;}但是

c++ - 如何正确链接 boost::mpl::inherit_linearly 和 boost::mpl::inherit 以便解析占位符?

假设我有这些类型:templateclassStorage>structAbstractFactoryUnit{virtual~AbstractFactoryUnit(){}virtualtypenameStorage::StoredTypedoCreate(Storage)=0;};和templateclassProductStorage,templateclass>classUnit=AbstractFactoryUnit>structAbstractFactory:boost::mpl::inherit_linearly>>::type{typedefTypeSequencePr

c++ - "a struct has public inheritance by default"

“默认情况下结构具有公共(public)继承”这句话的真正含义是什么?为什么下面的代码错误只是因为我在从c派生类d时省略了关键字'public'??structc{protected:inti;public:c(intii=0):i(ii){}virtualc*fun();};c*c::fun(){coutfun();} 最佳答案 意思是structc;structd:c相当于structd:publicc您的代码是一个类,扩展了一个结构:structc;classd:c;相当于classd:privatec;因为class默认有私

ios - fatal error : unexpectedly found nil while unwrapping an Optional value in inheriting class

我创建了一个CustomTopTabbarController来自定义标签栏。@objcMemberspublicclassCustomTopTabbarController:UITabBarController{@IBOutletweakvarcustomBar:UITabBar!publicoverridefuncviewDidLoad(){super.viewDidLoad()customBar.frame=CGRect(x:0,y:0,width:customBar.frame.size.width,height:customBar.frame.size.height)}pub

ios - Realm +地幔: how to avoid multiple inheritance duplication when integrating both frameworks?

我有一个简单的场景,我想用Mantle从Json解析一个用户模型并将其保存到Realm数据库:为了使用Mantle库,模型接口(interface)必须像这样扩展MTLModel类:@interfaceUser:MTLModel@property(nonatomic,copy)NSString*name;@property(nonatomic,copy)NSString*email;@end为了在Realm中保留该模型,我必须声明从RLMObject扩展的第二个接口(interface):@interfaceRLMUser:RLMObject@property(nonatomic,co

PHP 反射 : How to know if a method/property/constant is inherited from trait?

我想从列表中排除特征的所有继承方法未在类中被覆盖那么如何知道一个类成员是否继承自trait?是的,我可以这样检查:if($trait->hasMethod($methodName)||$ref->getTraitAliases()[$methodName]!==null){//}但是如果类中的trait方法被重写了怎么办?怎么知道呢?一种方法是检查方法体是否相似,如果是,我可能会排除它,但是否有更好的方法来实现这一点? 最佳答案 一个更简单的方法是ReflectionMethod::getFileName()。这将返回特征的文件名,