multiple-inheritance

How to implement multiple inheritance in delphi?

倖福魔咒の 提交于 2019-11-26 16:54:56
问题 I'm doing a full rewrite of an old library, and I'm not sure how to handle this situation (for the sake of being understood, all hail the bike analogy): I have the following classes: TBike - the bike itself TBikeWheel - one of the bike's wheel TBikeWheelFront and TBikeWheelBack , both inherits from TBikeWheel and then implements the specific stuff they need on top of it This is pretty straightforward, but now I decide to create multiple kind of bikes, each bikes having it's own kinds of wheel

Are Mixin class __init__ functions not automatically called?

偶尔善良 提交于 2019-11-26 15:51:31
问题 I'd like to use a Mixin to always add some init functionality to my child classes which each inherit from different API base classes. Specifically, I'd like to make multiple different child classes that inherit from one of these different API-supplied base classes and the one Mixin, which will always have the Mixin initialization code executed in the same way, without code replication. However, it seems that the __init__ function of the Mixin class never gets called unless I explicitly call

How to make a Java class that implements one interface with two generic types?

妖精的绣舞 提交于 2019-11-26 15:50:45
I have a generic interface public interface Consumer<E> { public void consume(E e); } I have a class that consumes two types of objects, so I would like to do something like: public class TwoTypesConsumer implements Consumer<Tomato>, Consumer<Apple> { public void consume(Tomato t) { ..... } public void consume(Apple a) { ...... } } Apparently I can't do that. I can of course implement the dispatch myself, e.g. public class TwoTypesConsumer implements Consumer<Object> { public void consume(Object o) { if (o instanceof Tomato) { ..... } else if (o instanceof Apple) { ..... } else { throw new

multiple inheritance: unexpected result after cast from void * to 2nd base class

久未见 提交于 2019-11-26 14:33:58
问题 My program needs to make use of void* in order to transport data or objects in dynamic invocation situation, so that it can reference data of arbitrary types, even primitive types. However, I recently discovered that the process of down-casting these void* in case of classes with multiple base classes fails and even crashes my program after invoking methods on these down casted pointers even if the memory addresses seem to be correct. The crash happens during access to "vtable". So I have

Should C# have multiple inheritance? [closed]

荒凉一梦 提交于 2019-11-26 13:01:58
I have come across numerous arguments against the inclusion of multiple inheritance in C#, some of which include (philosophical arguments aside): Multiple inheritance is too complicated and often ambiguous It is unnecessary because interfaces provide something similar Composition is a good substitute where interfaces are inappropriate I come from a C++ background and miss the power and elegance of multiple inheritance. Although it is not suited to all software designs there are situations where it is difficult to deny it's utility over interfaces, composition and similar OO techniques. Is the

Triple inheritance causes metaclass conflict… Sometimes

99封情书 提交于 2019-11-26 12:58:59
问题 Looks like I stumbled upon a metaclass hell even when I didn\'t wanted anything to do with it. I\'m writing an app in Qt4 using PySide. I want to separate event-driven part from UI definition, which is generated from Qt Designer files. Hence I create a \"controller\" classes, but to ease my life I multiple-inherit them anyways. An example: class BaseController(QObject): def setupEvents(self, parent): self.window = parent class MainController(BaseController): pass class MainWindow(QMainWindow,

Object layout in case of virtual functions and multiple inheritance

三世轮回 提交于 2019-11-26 12:57:01
问题 I was recently asked in an interview about object layout with virtual functions and multiple inheritance involved. I explained it in context of how it is implemented without multiple inheritance involved (i.e. how the compiler generated the virtual table, insert a secret pointer to the virtual table in each object and so on). It seemed to me that there was something missing in my explanation. So here are questions (see example below) What is the exact memory layout of the object of class C.

python multiple inheritance from different paths with same method name

↘锁芯ラ 提交于 2019-11-26 12:43:21
问题 With the following code sample, can super be used, or C has to call A.foo and B.foo explicitly? class A(object): def foo(self): print \'A.foo()\' class B(object): def foo(self): print \'B.foo()\' class C(A, B): def foo(self): print \'C.foo()\' A.foo(self) B.foo(self) 回答1: super() will only ever resolve a single class type for a given method, so if you're inheriting from multiple classes and want to call the method in both of them, you'll need to do it explicitly. i.e. A.foo(self) 回答2: super

Is super() broken in Python-2.x? [closed]

心不动则不痛 提交于 2019-11-26 12:38:29
问题 It\'s often stated that super should be avoided in Python 2. I\'ve found in my use of super in Python 2 that it never acts the way I expect unless I provide all arguments such as the example: super(ThisClass, self).some_func(*args, **kwargs) It seems to me this defeats the purpose of using super() , it\'s neither more concise, or much better than TheBaseClass.some_func(self, *args, **kwargs) . For most purposes method resolution order is a distant fairy tale. Other than the fact that 2.7 is

&#39;Inaccessible direct base&#39; caused by multiple inheritance

前提是你 提交于 2019-11-26 12:27:46
问题 Spoiler alert: Maybe a stupid question. :) #include <iostream> using namespace std; class Base { public: virtual void YourMethod(int) const = 0; }; class Intermediate : private Base { public: virtual void YourMethod(int i) const { cout << \"Calling from Intermediate\" << i << \"\\n\"; } }; class Derived : private Intermediate, public Base { public: void YourMethod(int i) const { cout << \"Calling from Derived : \" << i << \"\\n\"; } }; int main() { } Can someone Explain to me why this throws