multiple-inheritance

c# multiple inheritance

无人久伴 提交于 2019-12-18 05:55:21
问题 I would like to achieve this in C# (Pseudocode) class A; class B : A; class C : A, B; ... A ac = (A)c; ... B bc = (B)c; Is this possible? 回答1: You do not need multiple inheritance in this particular case: If class C inherits only from B , any instance of class C can be cast to both B and A ; since B already derives from A , C doesn't need to be derived from A again: class A { ... } class B : A { ... } class C : B { ... } ... C c = new C(); B bc = (B)c; // <-- will work just fine without

Multiple inheritance casting from base class to different derived class

六月ゝ 毕业季﹏ 提交于 2019-12-18 04:34:33
问题 Let's assume there is such class hierarchy: class A //base class class B //interface class C : public A, public B Then C object is created: A *object = new C(); Is it possible to cast object to B ? Important: I assume I don't know that object is C. I just know that it implements interface B 回答1: No . This is not possible (direct casting from A* to B* ). Because the address of A and B are at different locations in class C . So the cast will be always unsafe and possibly you might land up in

Can Super deal with multiple inheritance?

左心房为你撑大大i 提交于 2019-12-18 01:18:09
问题 When inheriting from two objects like these class Foo(object): def __init__(self,a): self.a=a class Bar(object): def __init__(self,b): self.b=b I would normally do something like this class FooBar(Foo,Bar): def __init__(self,a,b): Foo.__init__(self,a) Bar.__init__(self,b) How does super know if I want to call both? and if so how will it know which argument to pass where. Or is it simply not possible to user super here? Even if Foo and Bar take the same arguments can super deal with this? Or

Python: Correct way to initialize when superclasses accept different arguments?

一世执手 提交于 2019-12-17 22:58:26
问题 If I've got three classes like this: class BaseClass(object): def __init__(self, base_arg, base_arg2=None): ... class MixinClass(object): def __init__(self, mixin_arg): ... class ChildClass(BaseClass, MixinClass): def __init__(self, base_arg, mixin_arg, base_arg2=None): ??? What is the correct way to initialize MixinClass and BaseClass ? It doesn't look like I can use super because the MixinClass and the BaseClass both accept different arguments… And two calls, MixinClass.__init__(...) and

What are some good alternatives to multiple-inheritance in .NET?

人走茶凉 提交于 2019-12-17 22:35:00
问题 I've run into a bit of a problem with my class hierarchy, in a WPF application. It's one of those issues where you have two inheritance trees merging together, and you can't find any logical way to make your inheritance work smoothly without multiple inheritance. I'm wondering if anyone has any bright ideas for getting this kind of system working, without making it impossible to follow or debug. I'm a low-level engineer, so my first thought is always, "Oh! I'll just write some of these

How much interfaces a class file can implement [closed]

♀尐吖头ヾ 提交于 2019-12-17 20:35:05
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . How many interfaces can a class file implement? Is there a limit on the number of interfaces used by a class file? Thanks in advance. 回答1: For all practical purposes, there is no limit on the number of interfaces

does javascript support multiple inheritance like C++

匆匆过客 提交于 2019-12-17 20:27:37
问题 i know how to do inheritance in javascript but i can only inherit a single object. eg. function fun1() { this.var1=10; this.meth1=function() { ... ... }; } function fun2() { this.var2=20; this.meth2=function() { ... ... }; } function fun3() { this.var3=30; this.meth3=function() { ... ... }; } now if i want an fun3 object to inherit fun1 object i can do this fun3.prototype=new fun1(); or to inherit fun2 object i can do this fun3.prototype=new fun2(); but how can i inherit both fun1 and fun2 ?

Method resolution order in C++

孤街醉人 提交于 2019-12-17 18:56:57
问题 Consider the following class hierarchy: base class Object with a virtual method foo() an arbitrary hierarchy with multiple inheritance (virtual and non-virtual); each class is a subtype of Object; some of them override foo(), some don't a class X from this hierarchy, not overriding foo() How to determine which method will be executed upon a call of foo() on an object of class X in C++? (I'm looking for the algorithm, not any specific case.) 回答1: There is no MRO in C++ like Python. If a method

Multiple inheritance design issue in Java

徘徊边缘 提交于 2019-12-17 18:42:12
问题 How do you deal with having only single inheritance in java? Here is my specific problem: I have three (simplified) classes: public abstract class AbstractWord{ String kind; // eg noun, verb, etc public String getKind(){ return kind; } } public class Word extends AbstractWord{ public final String word; ctor... public void setKind(){ // based on the variable word calculate kind.. } } public class WordDescriptor extends AbstractWord{ ctor.. public void setKind(String kind){this.kind = kind;} }

Why is this an ambiguous MRO?

▼魔方 西西 提交于 2019-12-17 16:56:10
问题 class First(object): def __init__(self): print "first" class Second(First): def __init__(self): print "second" class Third(First, Second): def __init__(self): print "third" Source Why can't Python create a consistent MRO? It seems to me it's pretty clear: Search in First if method does not exist in Third Search in Second if method does not exist in First But if you try it out: TypeError: Error when calling the metaclass bases Cannot create a consistent method resolution order (MRO) for bases