标签: multiple-inheritance

15
推荐指数
1
解决办法
1万
查看次数

移动构造函数和多重继承

概要

当类使用多重继承时,如何安全地设计移动构造函数?

细节

请考虑以下情形:

struct T { };
struct U { };

struct X : public T, public U
{
    X(X&& other)
      : T(std::move(other))
      , U(std::move(other)) // already moved?!
    {
    }
};
Run Code Online (Sandbox Code Playgroud)

有没有办法移动 - 构建TU安全?

c++ multiple-inheritance move-constructor move-semantics c++11

15
推荐指数
1
解决办法
1826
查看次数

Do Derived1::Base and Derived2::Base refer to the same type?

MSVC, Clang and GCC disagree on this code:

struct Base { int x; };
struct Der1 : public  Base {};
struct Der2 : public  Base {};

struct AllDer : public Der1, public Der2 {
    void foo() {
        Der1::Base::x = 5;
    }
};
Run Code Online (Sandbox Code Playgroud)

Godbolt

GCC:

<source>: In member function 'void AllDer::foo()':    
<source>:10:21: error: 'Base' is an ambiguous base of 'AllDer'    
   10 |         Der1::Base::x = 5;    
      |                     ^    
Compiler returned: 1
Run Code Online (Sandbox Code Playgroud)

Clang gives a similar error, and MSVC gives no error.

Who …

c++ multiple-inheritance qualified-name diamond-problem language-lawyer

15
推荐指数
2
解决办法
253
查看次数

VB .Net中是否可以进行多重继承?

VB .Net中是否可以进行多重继承?如果是这样,语法是什么?

vb.net inheritance multiple-inheritance

14
推荐指数
1
解决办法
3万
查看次数

为什么在使用super()时我必须指定自己的类,有没有办法解决它?

使用Python super()进行方法链接时,必须明确指定自己的类,例如:

class MyDecorator(Decorator):
    def decorate(self):
        super(MyDecorator, self).decorate()
Run Code Online (Sandbox Code Playgroud)

我必须指定我的类的名称MyDecorator作为参数super().这不是DRY.当我重命名我的课程时,我将不得不重命名它两次.为什么这样实现?有没有办法避免必须两次(或更多)写出类的名称?

python multiple-inheritance

14
推荐指数
2
解决办法
2731
查看次数

绑定IList <IMyInterfaceType>不显示IMyInterface继承的接口成员

我将IList绑定到GridView.IMyInterface看起来像

public interface IMyInterface: IHasTotalHours, IHasLines
{
    DateTime GoalStartDate { get; set; }
    DateTime GoalEndDate { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我将一个实例绑定到Grid,如下所示:

IList<IMyInterface> instance= GetMyData();

myGrid.DataSource = instance;
myGrid.DataBind();
Run Code Online (Sandbox Code Playgroud)

将此绑定到网格时,显示在网格中的唯一成员是IMyInterface的直接成员:GoalStartDate和GoalEndDate.

这是为什么?如何让网格显示其继承的其他接口的成员?

更新 继承的接口定义简单的数据属性,如

public interface IHasTotalHours
{
    string Description { get; set; }
    int Hours{ get; set; }
}
public interface IHasLines
{
    double TotalLines { get; set; }
    double LinesPerHour { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

有一个实现IMyInterface的类:

public class MyClass : IMyInterface
{
    public string Description { get; set; }
    public …
Run Code Online (Sandbox Code Playgroud)

data-binding reflection interface multiple-inheritance typedescriptor

14
推荐指数
1
解决办法
1222
查看次数

如何在delphi中实现多重继承?

我正在完全重写一个旧库,我不知道如何处理这种情况(为了理解,所有人都欢呼自行车比喻):

我有以下课程:

  • TBike - 自行车本身
  • TBikeWheel - 自行车的一个轮子
  • TBikeWheelFront并且TBikeWheelBack,它们都从它继承TBikeWheel并实现了它们所需的特定内容

这非常简单,但现在我决定制造多种自行车,每辆自行车都有自己的轮子 - 它们和普通的前轮/后轮一样,加上特定的自行车.

  • TBikeXYZ - 继承自 TBike
  • TBikeWheelXYZ - 继承自 TBikeWheel

这是我的问题:TBikeWheelFrontXYZ应该继承TBikeWheelXYZ(以获得XYZ轮的特定方法),但它也应该继承TBikeWheelFront(以获得前轮的特定方法).

我的问题是,如何以不这样的方式实现它:

  1. 感觉就像一个黑客
  2. 强迫我多次重写相同的代码

delphi multiple-inheritance

14
推荐指数
4
解决办法
1万
查看次数

C++ - 在不使用RTTI/dynamic_cast的情况下向下转换钻石形状的继承对象

我目前正致力于在非RTTI平台(Android)上集成使用大量RTTI内容的第三方软件包.基本上,我做了自己的RTTI实现,但我遇到了问题.

问题是很多类都有钻石继承问题,因为所有类派生自相同的基类(对象)..所以,如果我想从基类转发到派生类,我必须使用一个dynamic_cast - 但RTTI不可用!当没有dynamic_cast的虚拟继承时,如何将对象从父对象转换为子对象?

它看起来像这样:

class A 
{
public:
 virtual char* func() { return "A"; };
};
class B : public virtual A
{
public:
 //virtual char* func() { return "B"; };
};
class C : public virtual A 
{
public:
 //virtual char* func() { return "C"; };
};

class D : public B, public C 
{
public:
 //virtual char* func() { return "D"; };
};

D d;
A* pa = static_cast<A*>(&d);
D* pd = static_cast<D*>(pa); // can't do that! …
Run Code Online (Sandbox Code Playgroud)

c++ casting multiple-inheritance rtti diamond-problem

14
推荐指数
2
解决办法
9261
查看次数

使用super调用多个父类的init?

可能重复:
Super可以处理多重继承吗?

Python继承?我有一个类结构(下面),并希望子类调用__init__父双方.这可能是以"超级"方式做的还是只是一个可怕的想法?

class Parent1(object):
    def __init__(self):
        self.var1 = 1

class Parent2(object):
    def _init__(self):
        self.var2 = 2

class Child(Parent1, Parent2):
    def __init__(self):
        ## call __init__ of Parent1
        ## call __init__ of Parent2
        ## super(Child, self).__init__()
Run Code Online (Sandbox Code Playgroud)

python init multiple-inheritance super new-style-class

14
推荐指数
3
解决办法
1万
查看次数

什么是多重继承?

我将以下内容称为"多重继承":

  • 通过继承一个或多个后代,直接继承一次类,间接继承一次或多次
  • 通过继承两个或多个后代来间接继承一个类两次或更多次

我想知道它是否存在以及如何明确地访问嵌入的子对象.

1.)[ 专业C++,2 编] 中指明了编译程序不能有直接继承其两个直接父类和所述父的父类.这是真的吗?

鉴于a GrandParentParent,扩展GrandParent,VC12和g ++允许a GrandChild直接从两者ParentGrandParent.继承.在VC12和g ++中,可以按如下方式定义这些类:

GrandParent声明一个int num数据成员.除继承之外,Parent声明自己的.除了继承's和s 之外,它还声明了它自己.numGrandParentnumGrandChildnumParentGrandParentnum

VC12似乎允许明确的成员访问,但g ++只允许它在某些情况下.

#include <iostream>
using std::cout;
using std::endl;

struct GrandParent { int num; };
struct Parent : GrandParent { int num; };
struct GrandChild : GrandParent, Parent { int num; };

int main()
{
    GrandChild gc;
    gc.num = …
Run Code Online (Sandbox Code Playgroud)

c++ inheritance multiple-inheritance diamond-problem

14
推荐指数
1
解决办法
964
查看次数