multiple-inheritance

C++ Multiple Inheritance - why you no work?

邮差的信 提交于 2019-12-01 00:33:32
问题 I am trying to figure out an interesting multiple inheritance issue. The grandparent is an interface class with multiple methods: class A { public: virtual int foo() = 0; virtual int bar() = 0; }; Then there are abstract classes that are partially completing this interface. class B : public A { public: int foo() { return 0;} }; class C : public A { public: int bar() { return 1;} }; The class I want to use inherits from both of the parents and specifies what method should come from where via

In scala multiple inheritance, how to resolve conflicting methods with same signature but different return type?

旧时模样 提交于 2019-11-30 22:07:06
问题 Consider the code below: trait A { def work = { "x" } } trait B { def work = { 1 } } class C extends A with B { override def work = super[A].work } Class C won't compile in scala 2.10, because of "overriding method work in trait A of type => String; method work has incompatible type". How to choose one specific method? 回答1: I'm afraid there is no way to do that. The super[A].work way works only if A and B have the same return types. Consider this: class D extends B .... val test: List[B] =

Multiple inheritance and pure virtual functions

自作多情 提交于 2019-11-30 22:05:13
问题 The following code: struct interface_base { virtual void foo() = 0; }; struct interface : public interface_base { virtual void bar() = 0; }; struct implementation_base : public interface_base { void foo(); }; struct implementation : public implementation_base, public interface { void bar(); }; int main() { implementation x; } fails to compile with the following errors: test.cpp: In function 'int main()': test.cpp:23:20: error: cannot declare variable 'x' to be of abstract type 'implementation

why does vb.net not support multiple inheritance?

大兔子大兔子 提交于 2019-11-30 20:55:36
问题 I've seen some discussion on why c# does not implement multiple inheritance but very little as to why it isn't supported in vb. I understand that both c# and vb are compiled down to intermediary language and so they both need to share similar restrictions. The lack of multiple inheritance in VB seems to have been given as one reason for the lack of the feature in dot net. Does anyone know why VB doesn't support multiple inheritance? I'm hoping for a bit of history lesson and discussion on why

C++ Multiple Inheritance Memory Layout with “Empty classes”

流过昼夜 提交于 2019-11-30 20:08:25
I know the memory layout of multiple inheritance is not defined, so I should not rely on it. However, can I rely on it in a special case. That is, a class has only one "real" super class. All others are "empty classes", i.e., classes that neither have fields nor virtual methods (i.e. they only have non-virtual methods). In this case, these additional classes should not add anything to the memory layout of the class. (More concisely, in the C++11 wording, the class has standard-layout ) Can I infer that all the superclasses will have no offset? E.g.: #include <iostream> class X{ int a; int b; }

C++ virtual inheritance initializer list

可紊 提交于 2019-11-30 19:12:44
in the following code: class A { public: int x; A(int x):x(x){} }; class B: public virtual A { public: B(int x):A(x){} }; class C: public virtual A { public: C(int x):A(x){} }; class D: public B, public C { public: D(int x):B(x++), C(x++), A(x++){} }; two questions: Why do I need to add A(...) in D's initializer list? D(int x):B(x++), C(x++), A(x++){} and D(int x):A(x++), B(x++), C(x++){} both give the same result with cout<<D(10).x , why? Why do I need to add A(...) in D's initializer list? That's because virtual base subobjects must be initialized before all other subobjects. Since A does

Multiple inheritance is not supported in dotnet. But multiple interface supports? [duplicate]

谁都会走 提交于 2019-11-30 17:33:59
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: Multiple Inheritance in C# Multiple inheritance is not supported in dotnet. But multiple interface supports. Why this kind of behaviour exists. Any specific reasons?? 回答1: You can simulate multiple inheritance using interfaces. If multiple inheritance with classes were allowed, it would lead to the Diamond problem. For reasons multiple inheritance is not supported, I suggest you read Why doesn't C# support

Do interfaces solve the “deadly diamond of death” issue?

早过忘川 提交于 2019-11-30 14:48:21
Do interfaces solve the deadly diamond of death problem? I don't think so, for example: // A class implementing two interfaces Interface1 and Interface2. // Interface1 has int x=10 and Interface2 has int x = 20 public class MultipleInterface implements Interface1, Interface2{ public void getX(){ System.out.println(x); } } Here we get an ambiguous x . Though interfaces are a good way for solving method ambiguity, I guess they fail in the case of variables? Am I correct? If I am missing something, enlighten me. Rizwan Java resists the multiple Concrete/abstract class inheritance but not multiple

Using Qt signals and slots with multiple inheritance

被刻印的时光 ゝ 提交于 2019-11-30 13:10:29
I have a class ( MyClass ) that inherits most of its functionality from a Qt built-in object ( QGraphicsTextItem ). QGraphicsTextItem inherits indirectly from QObject . MyClass also implements an interface, MyInterface . class MyClass : public QGraphicsTextItem, public MyInterface I need to be able to use connect and disconnect on MyInterface* . But it appears that connect and disconnect only work on QObject* instances. Since Qt does not support multiple inheritance from QObject-derived classes, I cannot derive MyInterface from QObject . (Nor would that make much sense for an interface anyway.

Ambiguous injected class name is not an error

只愿长相守 提交于 2019-11-30 11:08:14
What I read in the C++ standard about injected class names contradicts (as I see it) with the behavior of a sample program I will present shortly. Here's what I read: From 3.4 (paragraph 3) The injected-class-name of a class (clause 9) is also considered to be a member of that class for the purposes of name hiding and lookup. From 9 (paragraph 2) A class-name is inserted into the scope in which it is declared immediately after the class-name is seen. The class-name is also inserted into the scope of the class itself; this is known as the injected-class-name. For purposes of access checking,