multiple-inheritance

Using parameter that implements multiple interfaces pre-generics

对着背影说爱祢 提交于 2020-08-03 12:09:48
问题 Suppose I have these interfaces: public interface I1 { void foo(); } public interface I2 { void bar(); } and the classes: public class A extends AParent implements I1, I2 { // code for foo and bar methods here } public class B extends BParent implements I1, I2 { // code for foo and bar methods here } public class C extends CParent implements I1 { // code for foo method here } Now, with generics I can have a method like: public <T extends I1 & I2> void method(T param) { param.foo(); param.bar(

Using parameter that implements multiple interfaces pre-generics

风流意气都作罢 提交于 2020-08-03 12:08:07
问题 Suppose I have these interfaces: public interface I1 { void foo(); } public interface I2 { void bar(); } and the classes: public class A extends AParent implements I1, I2 { // code for foo and bar methods here } public class B extends BParent implements I1, I2 { // code for foo and bar methods here } public class C extends CParent implements I1 { // code for foo method here } Now, with generics I can have a method like: public <T extends I1 & I2> void method(T param) { param.foo(); param.bar(

Multiple inheritance with arguments

社会主义新天地 提交于 2020-06-27 10:02:12
问题 I have been reading quite a bit about inheritance, but I can't seem to grasp why this gives me an error (using Python 2.7.x). class A(object): def __init__(self, value): super(A, self).__init__() print 'First %s' % value class B(object): def __init__(self, value): super(B, self).__init__() print 'Second %s' % value class Log(A, B): def __init__(self, a, b): A.__init__(self, a) B.__init__(self, b) print 'Log' x = Log(1000, 2222) // Error: __init__() takes exactly 2 arguments (1 given) #

Ambiguous type reference

限于喜欢 提交于 2020-06-17 03:01:53
问题 Why does this works : template <typename T> struct foo { }; struct A { typedef foo<A> type; }; struct B : public A { typedef foo<B> type; }; int main() { B::type john; return 0; } But not this : template <typename T> struct foo { }; template <typename T> struct Shared { typedef foo<T> type; }; struct A : public Shared<A> { }; struct B : public A, public Shared<B> { }; int main() { // g++ 4.5 says : // error: reference to 'type' is ambiguous B::type john; return 0; } In my code, foo is

Do Derived1::Base and Derived2::Base refer to the same type?

本小妞迷上赌 提交于 2020-05-12 11:38:01
问题 MSVC, Clang and GCC disagree on this code: struct Base { int x; }; struct Der1 : public Base {}; struct Der2 : public Base {}; struct AllDer : public Der1, public Der2 { void foo() { Der1::Base::x = 5; } }; Godbolt GCC: <source>: In member function 'void AllDer::foo()': <source>:10:21: error: 'Base' is an ambiguous base of 'AllDer' 10 | Der1::Base::x = 5; | ^ Compiler returned: 1 Clang gives a similar error, and MSVC gives no error. Who is right here? I suppose this is covered in [class

Warning: defaulted move assignment operator of X will move assign virtual base class Y multiple times

江枫思渺然 提交于 2020-05-10 06:41:11
问题 I'm catching a warning under Clang when testing a library under C++11. I've never come across the warning before and searching is not providing too much in the way of reading and research. The warning is shown below, and it appears to be related to multiple inheritance and a common base class. But I'm not clear on the details triggering the warning or what I should do to address it. My first question is, Is this a problem that needs to be addressed? Or is it a matter of efficiency alone? My

Pythonic way of returning instances of parent class from child

懵懂的女人 提交于 2020-04-18 05:47:39
问题 Under multiple inheritance, where the child always inherits from Mixin and some type of Thing , how do I get a method in Mixin to enable the child to return instances of the parent Thing ? The following code works by directly calling into the Method Resolution Order graph, but seems unpythonic. Is there a better way? class Thing1(object): def __init__(self, x=None): self.x = x class Thing2(object): def __init__(self, x=None): self.x = 2*x ... class Mixin(object): def __init__(self, numbers=(1

python multiple inheritance qustion

醉酒当歌 提交于 2020-03-27 08:26:33
问题 This is an interview example question I copied and modified from question 10 of: https://www.codementor.io/sheena/essential-python-interview-questions-du107ozr6 class A(object): def go(self): print("go A go!") def stop(self): print("stop A stop!") class B(A): def go(self): super(B, self).go() print("go B go!") class C(A): def go(self): super(C, self).go() print("go C go!") def stop(self): super(C, self).stop() print("stop C stop!") class D(B,C): def go(self): super(D, self).go() print("go D

Python abstract base classes and multiple inheritance [duplicate]

拟墨画扇 提交于 2020-02-24 19:01:34
问题 This question already has answers here : python abstractmethod with another baseclass breaks abstract functionality (2 answers) Closed 22 days ago . I am trying to create a python (3.5) class structure where I use abstract methods to indicate which methods should be implemented. The following works as expected: from abc import ABC, abstractmethod class Base(ABC): @abstractmethod def foo(self): pass class Derived(Base, object): # Inheriting from object probably is superfluous (?) pass Derived(

Python abstract base classes and multiple inheritance [duplicate]

此生再无相见时 提交于 2020-02-24 18:59:50
问题 This question already has answers here : python abstractmethod with another baseclass breaks abstract functionality (2 answers) Closed 22 days ago . I am trying to create a python (3.5) class structure where I use abstract methods to indicate which methods should be implemented. The following works as expected: from abc import ABC, abstractmethod class Base(ABC): @abstractmethod def foo(self): pass class Derived(Base, object): # Inheriting from object probably is superfluous (?) pass Derived(