草庐IT

继承权

全部标签

c++ - 来自不同特化的模板类继承

这是出于对C++规则的好奇而提出的问题,没有任何实际应用。在使用模板时,我创建了一个类层次结构,如下所示:#include//DeclarationtemplatestructA;//SpecializationforX=0templatestructA{virtualvoidfoo(){printf("A::foo()\n");}};//ExtendedgeneralizedimplementationtemplatestructA:publicA{virtualvoidfoo(){printf("A::foo()\n");}virtualvoidbar(){printf("A::b

c++ - 如何继承boost::geometry::model::point?

我想继承bg::model::point用自己的功能扩展它。*point*s应存储在rtree中.以下最小示例无法编译我的派生点(boost1.54,gcc4.7.2)的用法:#include#include#include#include#include#includenamespacebg=boost::geometry;namespacebgi=boost::geometry::index;namespaceboost{namespacegeometry{namespaceindex{//apparentlynecessary:templatestructindexable>{t

c++ - 多重继承 C++

这个问题在这里已经有了答案:C++virtualtablelayoutofMI(multipleinheritance)(2个答案)关闭9年前。关于这个有几个问题。但我对此仍然不清楚。考虑这种多重继承。classBase1{public:Base1();virtual~Base1();virtualvoidspeakClearly();virtualBase1*clone()const;protected:floatdata_Base1;};classBase2{public:Base2();virtual~Base2();virtualvoidmumble();virtualBase

c++ - 使代码更小以实现多重继承

我编写了一个非常小的程序,您可以在其中输入您是男孩还是女孩,然后它会打印出一条声明。我的主要问题是,从我的代码中,除了从基类复制和粘贴之外,还有什么更容易为女性编写的方法。这是我的代码#include#includeclassMan{protected:std::stringname;public:voidgetInfo(std::stringhName){name=hName;}voidshowInfo(){std::cout>tName;std::cout>choice;//ifhandlerif(choice=="boy"){person.getInfo(tName);perso

c++ - 如何继承带有模板的类?

这个问题在这里已经有了答案:Accessinginheritedvariablefromtemplatedparentclass[duplicate](2个答案)WhydoIhavetoaccesstemplatebaseclassmembersthroughthethispointer?(3个答案)关闭8年前。为什么下面的工作正常:classa{public:intn;};classb:publica{public:b(){n=1;}};intmain(){}但这不起作用:templateclassa{public:intn;};templateclassb:publica{publ

c++ - 如何用继承或模板(或其他任何东西?)

我的问题类似于:Can'tusemacrodefineclassinC++,但有点复杂:classABC{public:DECLARATION(ABC)private:voidABCFun1();voidABCFun2();//...andsoon}#defineDECLARATION(TYPE)\std::stringGetClassName()\{\returnstd::string(#TYPE);}\//themacrocangoesontodeclaremore//commoninterfaces,likeInitialize(),...etc.所以,重点是,我可以使用这个宏来

c++ - clang/g++ 与私有(private)继承和使用声明的区别

考虑以下代码:#includestructParams{};templatestructBase{intdata()const{return42;}};templateclassD,classP>structMiddle:privateD//mustbe'public'forg++{};structFinal:publicMiddle{usingBase::data;};intmain(){Finalf;std::cout此代码编译成功并打印42clang并在gcc上给我编译时错误'intBase::data()const[withT=Params]'isinaccessible在这种

c++ - 了解空继承类的未使用 typedef

我只是想了解我正在阅读的一些教程代码。我正在尝试学习一些Dx11代码,我正在学习的教程中包含设计为事件详细信息的类,以便在事件发生时传递给函数,例如鼠标按钮被按下。有一个空的基类EventArgs定义如下:classEventArgs{public:EventArgs(){};}这是由其他事件类继承的。因此,例如,他们有一个按键事件参数类,如下所示:classKeyEventArgs:publicEventArgs{public:typedefEventArgsbase;KeyEventArgs(/**/){}//Restoftheclass}我理解所有事件都继承一个基础来表示“它们是

c++ - 在继承的构造函数中仅 move 类参数

以下代码无法编译GCC6.1,但适用于Clang3.8.0和VisualStudio2015:#includeclassbase{public:base(std::unique_ptr){}};classderived:publicbase{public:usingbase::base;};intmain(){deriveddf(std::make_unique());}出现以下错误:main.cpp:Inconstructor'derived::derived(std::unique_ptr)':main.cpp:10:17:error:useofdeletedfunction'st

c++ - 虚继承中构造函数的调用顺序是怎样的?

c++虚继承中构造函数的调用顺序是怎样的?针对下面两种多重继承的情况;(I)对于下面的代码,没有虚继承;classa{public:a(){cout输出是:ababcabcdef(II)类e虚继承:classa{public:a(){cout输出是:abcabcdeabf谁能解释一下这两种情况下的输出是如何获得的?虚继承如何影响对象的构造? 最佳答案 首先初始化虚基类,否则直接基类按照基类声明从左到右的顺序初始化。对于类f,classf:publicb,publice,没有虚基类,直接基类b会是首先初始化,然后是e。(从左到右的顺序