草庐IT

inheritence

全部标签

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++ - 使用 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

c++ - 如何 "inherit"来自 STL 类的迭代器?

我正在尝试使用我编写的一些算法创建一个名为tableaux的对象类,它们本质上是无符号整数vector的vector(它们类似于矩阵,只是行的长度可以不同)。主要问题是我想从vector类继承这些对象的迭代器,但我不知道如何做。我看了几个相关的问题和答案,我很容易继承std::vector>公开的,但共识是,由于STL容器没有虚拟析构函数或其他原因,这是不好的。所以我决定尝试通过组合来“继承”。这是我要实现的目标的一个最小示例:#include#includeclasstableau{private:std::vector>rep;public:usingstd::vector>::i

c++ 将 vector<Inherited*> 转换为 vector<abstract*>

classInterface{};classFoo:publicInterface{};classBar{public:vectorgetStuff();private:vectorstuff;};如何实现getStuff()函数? 最佳答案 vectorresult(stuff.begin(),stuff.end());returnresult; 关于c++将vector转换为vector,我们在StackOverflow上找到一个类似的问题: https:

c++ - 扩展公共(public)基础 : Diamond inheritance vs. QObject

我想我在这里遇到了一种菱形继承(钻石问题)问题。Qt提供了几个旋转框,用于整数值、double值以及日期/时间。它们都派生自QAbstractSpinBox:#includeclassQSpinBox:publicQAbstractSpinBox{};#includeclassQDoubleSpinBox:publicQAbstractSpinBox{};现在我想添加一些所有旋转框通用的功能,在这个具体示例中,一个按钮将旋转框恢复到其最小值(因此是specialValueText)。所以我也派生自QAbstractSpinBox并想出了这样的东西:classAbstractRevert