multiple-inheritance

Overcoming diamond ambiguity in different way

不问归期 提交于 2019-12-12 09:40:03
问题 I know the diamond problem and method to solve it using virtual base class. I tried to solve diamond problem in a different way but did not succeed. I don't know why. #include <iostream> using namespace std; class A { public: void display() { cout << "successfully printed"; } }; class B: public A { }; class C: private A // display() of A will become private member of C { }; class D: public B, public C // private member display() of C should not be inherited { }; int main() { D d; d.display();

Java: Why multiple interfaces instead of multiple inheritance? [duplicate]

梦想与她 提交于 2019-12-12 09:16:16
问题 This question already has answers here : Closed 8 years ago . Possible Duplicates: Why does Java allow multiple inheritance from interfaces but not from abstract/concrete classes Why there is no multiple inheritance in Java, but implementing multiple interfaces is allowed Instead of inheriting from multiple classes (which Java doesn't allow), why are we told to implement multiple interfaces instead? Surely the point of inheriting from multiple classes is the inherit their functionality - if

How to reuse code when multiple inheritance is not an option?

梦想的初衷 提交于 2019-12-12 09:14:57
问题 I would like to make use of few methods from couple of my old tested classes into my new class that I am building. Unfortunately, C# does not support multiple inheritance. How do I reuse code from these old classes? Do I just create them as member objects? or Do I have any other options? 回答1: Generally, using composition instead of inheritance is the way forward, yes. If you could give a concrete example of the kind of thing you mean, that would make it easier to help find the appropriate

Calling super class method in multiple inheritance

时光总嘲笑我的痴心妄想 提交于 2019-12-12 04:58:08
问题 I have the following code: class A: pass class B(A): def foo(self, a): if a: return 'B' return super(B, self).foo(a) class C: def foo(self, a): return 'C' class D(B, C): def foo(self, a): return super().foo(a) d = D() print(d.foo(0)) When I call d.foo(0) based on MRO it first calls the foo method of B class and inside that, if the condition is wrong and it will return super(B, self).foo(0) but class A has no foo method and I expect this error: AttributeError: 'super' object has no attribute

Why in Multiple Inheritance only one class init method get called [duplicate]

不问归期 提交于 2019-12-12 04:09:55
问题 This question already has answers here : How does Python's super() work with multiple inheritance? (14 answers) Closed 2 years ago . In Module a.py class Foo(object): def __init__(self): self.foo = 20 class Bar(object): def __init__(self): self.bar = 10 class FooBar(Foo, Bar): def __init__(self): print "foobar init" super(FooBar, self).__init__() a = FooBar() print a.foo print a.bar In multiple inheritances only first class init method getting called. Is there any way to call all init method

Python - multiple inheritance with same name

大城市里の小女人 提交于 2019-12-12 03:34:55
问题 I have main class as: class OptionsMenu(object): def __init__(self, name): try: self.menu = getattr(self, name)() except: self.menu = None @staticmethod def cap(): return ['a', 'b'] and have a child class override as: class OptionsMenu(OptionsMenu): @staticmethod def cap(): return ['a', 'b', 'c'] The first class gives the menu options for default template, while next gives for some other template. I want another class OptionsMenu derived from child class, and get the list ( ['a', 'b', 'c'] )

Doctrine, multi-level inheritance not hydrate

拈花ヽ惹草 提交于 2019-12-11 23:42:14
问题 When I create a class child# that I fill its values and that I save it in DB (persistent, flush) I have no worries, all is database. When I pick a Child# up from the database. All the attributes of the Parent1 are not hydrated, I do have those of the GrandParent, the Child# but not those of the Parent1, why? /** * @ORM\Entity * @ORM\InheritanceType("JOINED") * @ORM\DiscriminatorColumn(name="class", type="int") * @ORM\DiscriminatorMap({ * 0 = "Parent2", * 1 = "Child1", * 2 = "Child2"}) */

Multiple Inheritance Class References

主宰稳场 提交于 2019-12-11 17:59:38
问题 Suppose I have a pair of base classes: class A {}; class B { virtual void foo(A* ref); virtual void foo2(A* ref); }; And from them, a few derived classes: class C : virtual public A { int data; }; class D : public B { virtual void foo(A* ref) { ((C*) (ref)).data = 5; } }; class E : virtual public A { int otherData; }; class F : public B { virtual void foo2(A* ref) { ((E*) (ref)).otherData = 6; } }; And finally, we have a class that follows suit, as such: class G : public E, public C { }; with

PySide Multiple Inheritance: Inheriting a QWidget and a Mixin

半世苍凉 提交于 2019-12-11 12:24:21
问题 I'm trying to create a set of PySide classes that inherit QWidget, QMainWindow, and QDialog. Also, I would like to inherit another class to overrides a few functions, and also set the layout of the widget. Example: Mixin: class Mixin(object): def __init__(self, parent, arg): self.arg = arg self.parent = parent # Setup the UI from QDesigner ui = Ui_widget() ui.setupUi(self.parent) def setLayout(self, layout, title): self.parent.setWindowTitle(title) self.parent.setLayout(layout) def

neo4django multiple inheritance

做~自己de王妃 提交于 2019-12-11 12:07:27
问题 I was trying to create my model MyUser extending neo4django.auth.models.User, so I can use the underlying authentication system. The problem is I want create also a superclass from which derive many methods and attributes that are very common for my different kind of nodes. I did this: from neo4django.auth.models import User as AuthUser class MyBaseModel(models.NodeModel): .... class Meta: abstract = True class MyUser(MyBaseModel,AuthUser): ... but any operation on the model gives me