草庐IT

inherited-constructors

全部标签

c++ - 类型特征 : Check if class have specific function (maybe inherit)

我知道有很多方法可以检测一个类是否具有特定功能,但没有一种方法真正适合我的具体情况。我当前用于检查正确成员函数的实现工作正常,继承函数除外。#includetemplateclassHasFoo{templatestructCheck;templatestaticstd::true_typeTest(Check*);templatestaticstd::false_typeTest(...);public:staticconstexprboolvalue=decltype(Test(0))::value;};structA{intfoo(float);};structB:publicA

c++ - 我想我已经重写了一个虚拟方法,但我仍然得到 : "X must implement the inherited pure virtual method Y"

我正在尝试用C++为我正在编写的游戏实现一个接口(interface),但我运行时出错。这是我创建的接口(interface)及其子类://Attack.h//definesasetofvaluesassociatedwithallattacks//andaninterfaceforallattackstypedefunsignedconstintattack_type;typedefunsignedconstintp_attack_type;//definestheattacktypesstaticconstattack_typeNORMAL=0;staticconstattack_

inheritance - 如何让数据类在 Kotlin 中实现接口(interface)/扩展父类(super class)属性?

我有几个数据类,其中包括varid:Int?字段。我想在interface或superclass中表达这一点,并让数据类扩展它并在构造时设置此id。但是,如果我尝试这样做:interfaceB{varid:Int?}dataclassA(varid:Int):B(id)它提示我正在覆盖id字段,我是哈哈..Q:在这种情况下,如何让数据类A在构造时获取一个id,并设置该id在interface或superclass中声明? 最佳答案 确实,您不需要abstractclass然而。您可以覆盖interface属性,例如:interfac

inheritance - 如何让数据类在 Kotlin 中实现接口(interface)/扩展父类(super class)属性?

我有几个数据类,其中包括varid:Int?字段。我想在interface或superclass中表达这一点,并让数据类扩展它并在构造时设置此id。但是,如果我尝试这样做:interfaceB{varid:Int?}dataclassA(varid:Int):B(id)它提示我正在覆盖id字段,我是哈哈..Q:在这种情况下,如何让数据类A在构造时获取一个id,并设置该id在interface或superclass中声明? 最佳答案 确实,您不需要abstractclass然而。您可以覆盖interface属性,例如:interfac

inheritance - 是否可以向 Kotlin 中的现有类添加接口(interface)?

有时创建一个已经由现有第三方代码(即来自库)实现的接口(interface)很有用。例如,我们可以想象选择String类的方法子集并声明一个GenericString。然后,我们可能会定义实现这些方法的其他GenericString,但不会定义String类的其他方法。唯一的问题是String类不继承自GenericString类。是否可以向Kotlin中的现有类添加接口(interface),或者我必须创建一个实现该接口(interface)的String子类? 最佳答案 不,很遗憾,不支持“扩展类型”。Kotlin论坛(here

inheritance - 是否可以向 Kotlin 中的现有类添加接口(interface)?

有时创建一个已经由现有第三方代码(即来自库)实现的接口(interface)很有用。例如,我们可以想象选择String类的方法子集并声明一个GenericString。然后,我们可能会定义实现这些方法的其他GenericString,但不会定义String类的其他方法。唯一的问题是String类不继承自GenericString类。是否可以向Kotlin中的现有类添加接口(interface),或者我必须创建一个实现该接口(interface)的String子类? 最佳答案 不,很遗憾,不支持“扩展类型”。Kotlin论坛(here

C++ 继承 : Calling Base Class Constructor In Header

假设类Child是类Parent的派生类。在一个五文件程序中,我如何在Child.h中指定我想调用Parent的构造函数?我认为header中的以下内容不合法:Child(intParam,intParamTwo):Parent(Param);在这种情况下,Child.cpp的构造函数语法应该是什么样的? 最佳答案 在Child.h中,您只需声明:Child(intParam,intParamTwo);在Child.cpp中,您将拥有:Child::Child(intParam,intParamTwo):Parent(Param){

c++ - 使用 mpl::inherit_linearly 定义接口(interface)的含义

我正在编写一些消息处理代码,其中每条消息都是一个POD结构。在写作方式上,这将是定义一个抽象基类,为每种消息类型使用虚拟函数,例如:classAbstractHandler{public:virtualvoidhandleMessage(constMessageType1&msg)=0;virtualvoidhandleMessage(constMessageType2&msg)=0;virtualvoidhandleMessage(constMessageType3&msg)=0;virtualvoidhandleMessage(constMessageType4&msg)=0;};

c++ - 避免模​​拟 std::fstream 类的 "inheritance by dominance"警告

我正在使用googlemock在我的单元测试中模拟一个std::fstream对象,像这样:TEST_F(SomeTest,SomethingIsDoneCorrectly){classMockFstream:publicstd::fstream{};MockFstreamlMockFstream;//Expectationsandassertionshere}当我编译时,我收到以下警告:Warning1warningC4250:'SomeTest_SomethingIsDoneCorrectly_Test::TestBody::MockFstream':inherits'std::b

constructor - 如何在 Kotlin 的构造函数 block 之外访问辅助构造函数参数

我是Kotlin的新手,正在学习可用的教程。但是现在我似乎对辅助构造函数有疑问:在主构造函数中声明的参数可以在函数中访问,但是当我尝试使用辅助构造函数中的参数执行此操作时,出现错误:未解析的引用:nbr代码:classTest(_name:String){valname:String=_nameconstructor(_name:String,_nbr:Int):this(_name){valnbr:Int=_nbr}funprintNameAndNumber(){println("Name:$name")println("Number:$nbr")}}我很清楚我做错了什么,但谁能告诉