multiple-inheritance

dynamic_cast of “this” inside constructor

强颜欢笑 提交于 2019-12-17 16:37:48
问题 This question is very similar to this one Why can't I dynamic_cast "sideways" during multiple inheritence?, except that the cast does work - just not inside in the constructor. Header: class A { public: virtual ~A() {} void printA(); }; class B { public: B(); virtual ~B() {} void printB(); private: std::string message_; }; class C : public A, public B { public: C() {} virtual ~C() {} }; Source: void A::printA() { cout << "A" << endl; } B::B() { A* a = dynamic_cast< A* >( this ); if ( a ) {

Why can't I inherit from dict AND Exception in Python?

廉价感情. 提交于 2019-12-17 16:17:11
问题 I got the following class : class ConstraintFailureSet(dict, Exception) : """ Container for constraint failures. It act as a constraint failure itself but can contain other constraint failures that can be accessed with a dict syntax. """ def __init__(self, **failures) : dict.__init__(self, failures) Exception.__init__(self) print isinstance(ConstraintFailureSet(), Exception) True raise ConstraintFailureSet() TypeError: exceptions must be classes, instances, or strings (deprecated), not

Virtual Inheritance: Error: no unique final overrider

孤街浪徒 提交于 2019-12-17 15:52:13
问题 I know virtual inheritance is covered here before and before asking this question I went through the detail of the virtual inheritance and went through the details of a similar problem like the followings: multiple-diamond-inheritance-compiles-without-virtual-but-doesnt-with and why does gcc give me an error - final overrider My problem is slightly different as I am not using pure virtual function and explicitly using virtual inheritance to have one unique 'Base' class. The hierarchy is as

Two interfaces with same method signature implemented in Java class

狂风中的少年 提交于 2019-12-17 15:44:50
问题 I have two Java interfaces and one implementing class. (I have used Eclipse to run the program directly, and I did not try to check any compiler warning et cetera by explicitly compiling from the command line.) Why do they run without problem? Why does Java allow this, even when it satisfies the "contract" of both interfaces but create ambiguity in implementing class? Updated the example. public interface CassettePlayer { void play(); } public interface DVDPlayer { void play(); } public class

Multiple inheritance + virtual function mess

此生再无相见时 提交于 2019-12-17 10:45:30
问题 I have a diamond multiple inheritance scenario like this: A / \ B C \ / D The common parent, A, defines a virtual function fn(). Is it possible for both B and C to define fn() ? If it is, then the next question is - can D access both B and C's fn() without disambiguation? I'm assuming there is some syntax for this.. And is it possible for D to do that without knowing specifically who are B and C? B and C can be replaces by some other classes and I want the code in D to be generic. What I'm

Is Multiple Inheritance allowed at class level in PHP?

旧城冷巷雨未停 提交于 2019-12-17 10:34:35
问题 Is Multiple Inheritance allowed at class level in PHP? 回答1: Multiple inheritance suffers from the Diamond Problem, which has not been (agreed upon how to be) solved in PHP yet. Thus, there is no multiple inheritance in PHP . BaseClass /\ / \ ClassA ClassB \ / \/ ClassC If both ClassA and ClassB defined their own method foo() , which one would you call in ClassC ? You are encouraged to either use object composition or interfaces (which do allow multiple inheritance) or - if you are after

Can one class extend two classes?

微笑、不失礼 提交于 2019-12-17 10:23:01
问题 My class should extend two classes at the same time: public class Preferences extends AbstractBillingActivity { public class Preferences extends PreferenceActivity { How to do so? Upd . Since this is not possible, how should I use that AbstractBillingActivity with Preferences then? Upd2 . If I go with interfaces, should I create: BillingInterface public interface BillingInterface extends PreferenceActivity, AbstractBillingActivity { } PreferenceActivity public interface PreferenceActivity { }

How to reference a generic return type with multiple bounds

爱⌒轻易说出口 提交于 2019-12-17 09:18:28
问题 I have recently seen that one can declare a return type that is also bounded by an interface. Consider the following class and interface: public class Foo { public String getFoo() { ... } } public interface Bar { public void setBar(String bar); } I can declare a return type like this: public class FooBar { public static <T extends Foo & Bar> T getFooBar() { //some implementation that returns a Foo object, //which is forced to implement Bar } } If I call that method from somewhere, my IDE is

Python's Multiple Inheritance: Picking which super() to call

一个人想着一个人 提交于 2019-12-17 09:09:54
问题 In Python, how do I pick which Parent's method to call? Say I want to call the parent ASDF2's __init__ method. Seems like I have to specify ASDF1 in the super()..? And if I want to call ASDF3's __init__ , then I must specify ASDF2 ?! >>> class ASDF(ASDF1, ASDF2, ASDF3): def __init__(self): super(ASDF1, self).__init__() >>> ASDF() ASDF2's __init__ happened >>> class ASDF(ASDF1, ASDF2, ASDF3): def __init__(self): super(ASDF2, self).__init__() >>> ASDF() ASDF3's __init__ happened Seems bonkers

Python's Multiple Inheritance: Picking which super() to call

我只是一个虾纸丫 提交于 2019-12-17 09:09:07
问题 In Python, how do I pick which Parent's method to call? Say I want to call the parent ASDF2's __init__ method. Seems like I have to specify ASDF1 in the super()..? And if I want to call ASDF3's __init__ , then I must specify ASDF2 ?! >>> class ASDF(ASDF1, ASDF2, ASDF3): def __init__(self): super(ASDF1, self).__init__() >>> ASDF() ASDF2's __init__ happened >>> class ASDF(ASDF1, ASDF2, ASDF3): def __init__(self): super(ASDF2, self).__init__() >>> ASDF() ASDF3's __init__ happened Seems bonkers