草庐IT

Derived_A

全部标签

c++ - 警告 : overloaded virtual function "Base::process" is only partially overridden in class "derived"

我低于警告。我的部分代码是:classBase{public:virtualvoidprocess(intx){;};virtualvoidprocess(inta,floatb){;};protected:intpd;floatpb;};classderived:publicBase{public:voidprocess(inta,floatb);}voidderived::process(inta,floatb){pd=a;pb=b;....}我低于警告:Warning:overloadedvirtualfunction"Base::process"isonlypartiallyo

c++ - 为什么不能将 Base 类对象分配给 Derived 类对象?

派生类对象可以分配给C++中的基类对象。Derivedd;Baseb=d;//It'sOk但为什么不能将基类对象赋值给派生类对象呢?Baseb;Derivedd=b;//NotOk.Compilergiveanerror编辑:抱歉,这个问题实际上是在面试时被问到的。 最佳答案 继承是一种“is-a”关系,但它是单向。如果你有例如structBase{/*...*/};structDerived:Base{/*...*/};那么Derived是一个Base,但是Base不是Derived.这就是为什么您可以使用派生对象分配或初始化基类

c++ - 从 Derived** 到 Base*const* 的转换

请在链接parashift之前阅读我的问题,我可以谷歌搜索,这种情况略有不同。这是不允许的Child**cc;Base**bb=cc;因为你可以做到*bb=newOtherChild;但是如果我们有Child**cc;constBase*const*constbb=cc;我不认为所有这些常量对于我的示例都是必需的,但只是为了确定..我认为应该工作的最低限度是Base*const*bb=cc;那你不能这样做*bb=newOtherChild;所以应该是安全的。但为什么不允许呢? 最佳答案 你混淆了两种情况:添加const上行虽然形式上

c++ - 无法将 "member pointer to derived class"转换为 "member pointer to base class"

使用指向基类的指针调用类的虚成员函数当然是C++中非常常见的事情。所以我觉得很奇怪,当你有一个成员指针而不是一个普通指针时,似乎不可能做同样的事情。请考虑以下代码:structB{virtualvoidf();};structD:B{virtualvoidf();};structE{Bb;Dd;};intmain(){Ee;//Firstwithnormalpointers:B*pb1=&e.b;//OKB*pb2=&e.d;//OK,BisabaseofDpb1->f();//OK,callsB::f()pb2->f();//OK,callsD::f()//Nowwithmember

c++ - 是否存在将实际 Base 向下转换为 Derived 的情况?

在一般情况下,从(动态)Base向下转换到派生类之一Derived是(当之无愧的)未定义行为明显的UBclassBase{public:virtualvoidfoo(){/*doessomething*/ }inta;}classDerived:publicBase{public:virtualvoidfoo(){/*doessomethingdifferent*/ }doubleb;}Baseobj;DerivedderObj=*static_cast(&obj);//在目前编译器的实现方式中,这里显然至少会存在Vtable和b值不一致的问题,其中包含垃圾值。因此,标准没有定义这些条

C++ 函数模板 : Derived and explicit return type

我有以下问题,我只是没有找到合适的解决方案(也许没有):我有一个模板化方法,其中返回类型取决于输入类型,感谢C++11decltype返回类型可以很容易地导出,但是如果需要,我还希望允许用户明确定义返回类型。更正式地说,我有一个模板化函数f,我想被调用为f(x),既没有显式定义输入类型,也没有显式定义返回类型。我也希望能够将其称为fx()明确定义返回类型,但输入类型仍然自动派生。现在,用C++11满足第一个约束很容易(假设还有另一个模板化方法:templateautof(constInT&in)->decltype(/*codederivingthereturntypeusingin*

c# - "Base b = new Derived()"是哪个 OO 概念的一个例子?

我在通过考试时遇到了一个问题,但我的同事未能就此问题达成一致。С++1classBase{};2classDerived:publicBase{};3classFoo4{5public:6Foo()7{-8-Base*b=newDerived();//Conceptnameis?9}10};C#1abstractclassBase{}2publicclassDerived:Base{}34publicclassFoo5{6publicFoo7{-8-Baseb=newDerived();//Conceptnameis?9}10}问题是:上面第8行是下面oo概念的一个例子多态性聚合封装抽

c++ - Eigen,如何访问 MatrixBase<Derived> 的底层数组

我需要访问包含MatrixBaseEigen矩阵数据的数组。Eigen库有data()方法,它返回一个指向数组的指针,但是它只能从矩阵访问type.MatrixBase没有类似的方法,即使MatrixBase类应该充当模板并且实际类型应该只是一个Matrix。如果我尝试访问MatrixBase.data(),我会收到编译时错误:templatevoiduscgemv(floatalpha,constUSCMatrix&a,constMatrixBase&b,constMatrixBase&c_const){//...somecodefloat*bMat=b.data();///more

c++ - "most derived object"是什么意思?

C++03标准声明§1.8[intro.object]/4:Ifacompleteobject,adatamember(9.2),oranarrayelementisofclasstype,itstypeisconsideredthemostderivedclass,todistinguishitfromtheclasstypeofanybaseclasssubobject;anobjectofamostderivedclasstypeiscalledamostderivedobject.谁能阐明“最衍生的对象”?一些示例将不胜感激。 最佳答案

MySQL 错误 : #1248 - Every derived table must have its own alias

如何通过设置别名来更正此错误?错误:#1248-每个派生表都必须有自己的别名SELECTentry_id,author_id,title,statusFROMexp_channel_titlesLEFTJOIN(SELECTentry_id,field_id_14,field_id_15,field_id_25,field_id_27,field_id_28,field_id_29,field_id_30,field_id_31,field_id_32,field_id_33,field_id_34,field_id_35FROMexp_channel_dataWHEREentry_i