草庐IT

inherited

全部标签

c++ - 两阶段查找 : is it possible to easily mix inheritence and templates

简介:C++标准区分依赖模板参数的符号名称和不依赖模板参数的名称,这称为两阶段名称查找(参见here)。定义模板时,会尽快解析非相关名称。另一方面,从属名称仅在模板实例化时解析。示例:templatestructBase{typedefTtype;staticconstintn=3;virtualintf()=0;intf(intx){returnx*2;}};//doesn'tcompile!templatestructDerived:Base{typefield;//Thecompilerdoesn'tknowBase::typeyet!intf(){returnn;}//thec

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# 编码 C++ 结构继承

假设我在C++中有以下结构structBase{USHORTsize;}structInherited:publicBase{BYTEtype;}我想在C#中编码Inherited但结构继承在C#中不起作用。做以下是否合适?publicinterfaceIBase{ushortSize{get;set;}}[StructLayout(LayoutKind.Sequential)]publicstructInherited:IBase{publicushortSize{get;set;}publicbyteType{get;set;}}我在这里简化了问题,我的结构更大,因此很难验证结果。

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