multiple-inheritance

two interfaces, multiple inheritance combine into one container?

不问归期 提交于 2020-01-05 00:00:52
问题 I stumbled upon the following problem: I have two packages A and B working fine for each own. Each has its own interface and his own implementation. Now i made a package C combining a adapter of A with a concrete Implemenation of B. C actually only implements the Interface of A and is only inheritating and using the Interface of B internally for now. Most of the times that was enough to have only access to the Interface A from a Container, but now i need the methods from B accessible too.

Is there any way to achieve multiple inheritance in php?

蓝咒 提交于 2020-01-03 17:16:49
问题 Lets say I have a parent class class parent { } ..... This parent has three sub class class child1 { } class child2 { } class child3 { } and these child classes have further smaller parts like class child1subpar1 { } class child1subpar2 { public function foo() { echo "hi"; } } class child2subpar1 { } class child2subpar2 { } Now, how to sum this whole up like class child1 extends child1subpar1, child1subpar2 { } class child2 extends child2subpar1, childsubpar1 { } class parent extends child1

Controlling read/write access to fields

爷,独闯天下 提交于 2020-01-02 23:00:45
问题 Suppose that we would like to separate out the read and write access in an interface pattern as below. namespace accesspattern { namespace ReadOnly { public interface IA { double get_a(); } } namespace Writable { public interface IA : ReadOnly.IA { void set_a(double value); } } } This is easy to implement: namespace accesspattern { namespace ReadOnly { public class A : IA { protected double a; public double get_a() { return a; } } } namespace Writable { public class A : ReadOnly.A, IA {

Does this pointer adjustment occur for non-polymorphic inheritance?

为君一笑 提交于 2020-01-02 10:01:14
问题 Does non-polymorphic inheritance require this pointer adjustment? In all the cases I've seen this pointer adjustment discussed the examples used involved polymorphic inheritance via keyword virtual . It's not clear to me if non-polymorphic inheritance would require this pointer adjustment. An extremely simple example would be: struct Base1 { void b1() {} }; struct Base2 { void b2() {} }; struct Derived : public Base1, Base2 { void derived() {} }; Would the following function call require this

Does this pointer adjustment occur for non-polymorphic inheritance?

隐身守侯 提交于 2020-01-02 10:01:11
问题 Does non-polymorphic inheritance require this pointer adjustment? In all the cases I've seen this pointer adjustment discussed the examples used involved polymorphic inheritance via keyword virtual . It's not clear to me if non-polymorphic inheritance would require this pointer adjustment. An extremely simple example would be: struct Base1 { void b1() {} }; struct Base2 { void b2() {} }; struct Derived : public Base1, Base2 { void derived() {} }; Would the following function call require this

Multiple inheritance pointer comparison

邮差的信 提交于 2020-01-02 00:46:05
问题 I have a class Derived that inherits directly from two base classes, Base1 and Base2 . I'd like to know if it's safe, in general, to compare pointers to the base classes to determine if they are the same Derived object: Base1* p1; Base2* p2; /* * Stuff happens here. p1 and p2 now point to valid objects of either their * base type or Derived */ //assert(p1 == p2); //This is illegal assert(p1 == static_cast<Base1*>(p2)); //Is this ok? assert(static_cast<Derived*>(p1) == static_cast<Derived*>(p2

TypeErrors using metaclasses in conjunction with multiple inheritance

可紊 提交于 2020-01-01 14:56:39
问题 I have two questions converning metaclasses and multiple inheritance. The first is: Why do I get a TypeError for the class Derived but not for Derived2 ? class Metaclass(type): pass class Klass(object): __metaclass__ = Metaclass #class Derived(object, Klass): pass # if I uncomment this, I get a TypeError class OtherClass(object): pass class Derived2(OtherClass, Klass): pass # I do not get a TypeError for this The exact error message is: TypeError: Error when calling the metaclass bases Cannot

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call

与世无争的帅哥 提交于 2020-01-01 09:17:37
问题 I created a simple program that demonstrates the runtime error I'm getting with my Qt application that uses multiple inheritance. The inheritance tree looks like: QGraphicsItem (abstract) \ QGraphicsLineItem MyInterface (abstract) \ / \ / MySubclass And here is the code: /* main.cpp */ #include <QApplication> #include <QGraphicsScene> #include <QGraphicsLineItem> //simple interface with one pure virtual method class MyInterface { public: virtual void myVirtualMethod() = 0; }; //Multiple

Why can't I create a default, ordered dict by inheriting OrderedDict and defaultdict?

拜拜、爱过 提交于 2020-01-01 08:27:01
问题 My first attempt to combine the features of two dictionaries in the collections module was to create a class that inherits them: from collections import OrderedDict, defaultdict class DefaultOrderedDict(defaultdict, OrderedDict): def __init__(self, default_factory=None, *a, **kw): super().__init__(default_factory, *a, **kw) However, I cannot assign an item to this dictionary: d = DefaultOrderedDict(lambda: 0) d['a'] = 1 Traceback (most recent call last): File "<stdin>", line 1, in <module>

Why is the diamond case with its common ancestor used to explain Java multiple inheritance issue, instead of two unrelated parent classes?

点点圈 提交于 2020-01-01 07:45:50
问题 This question might sound weird to Java people but if you try to explain this, it would be great. In these days I am clearing some of Java's very basic concept. So I come to Inheritance and Interface topic of Java. While reading this I found that Java does not support Multiple Inheritance and also understood that, what I am not able to understand that why everywhere Diamond figure issue(At least 4 class to create diamond) is discussed to explain this behavior, Can't we understand this issue