Questions tagged [multiple-inheritance]

A feature of some object-oriented computer programming languages in which a class can inherit behaviors and features from more than one superclass or base class.

Languages that support multiple inheritance include:

  • C++
  • Common Lisp (via CLOS)
  • Curl
  • Dylan
  • Eiffel
  • EuLisp (via The EuLisp Object System TELOS)
  • Logtalk
  • Object REXX
  • OCaml
  • Perl
  • Perl 6
  • Python
  • Scala (via the use of mixin classes)
  • Tcl (via Incremental Tcl)

Other object-oriented languages, such as Java and Ruby implement single inheritance, although protocols or "interfaces" provide some of the functionality of true multiple inheritance.

2710 questions
43
votes
9 answers

python multiple inheritance from different paths with same method name

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…
sayap
  • 6,169
  • 2
  • 36
  • 40
42
votes
2 answers

Triple inheritance causes metaclass conflict... Sometimes

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…
Red
  • 1,450
  • 2
  • 17
  • 33
40
votes
4 answers

Using parameter that implements multiple interfaces pre-generics

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…
Andrei Fierbinteanu
  • 7,656
  • 3
  • 31
  • 45
39
votes
7 answers

C++ diamond problem - How to call base method only once

I'm using multiple inheritance in C++ and extending base methods by calling their base explicitly. Assume the following hierarchy: Creature / \ Swimmer Flier \ / Duck Which corresponds to class Creature { …
O. Aroesti
  • 1,016
  • 11
  • 32
38
votes
6 answers

What are some good alternatives to multiple-inheritance in .NET?

I've run into a bit of a problem with my class hierarchy, in a WPF application. It's one of those issues where you have two inheritance trees merging together, and you can't find any logical way to make your inheritance work smoothly without…
Giffyguy
  • 20,378
  • 34
  • 97
  • 168
36
votes
8 answers

Trying to inherit three base classes and can't

I have a few questions related to the design of my User class but they are different enough that I think they should be independent questions. So, the first is related to inheritance of base classes. I am currently inheriting two classes,…
Peter
  • 5,251
  • 16
  • 63
  • 98
34
votes
2 answers

Abstract class + mixin + multiple inheritance in python

So, I think the code probably explains what I'm trying to do better than I can in words, so here goes: import abc class foo(object): __metaclass__ = abc.ABCMeta @abc.abstractmethod def bar(self): pass class…
mluebke
  • 8,588
  • 7
  • 35
  • 31
34
votes
2 answers

How does multiple inheritance work with the super() and different __init__() arguments?

I'm just diving into some more advanced python subjects (well, advanced to me at least). I am now reading about multiple inheritance and how you can use super(). I more or less understand the way the super function is used, but (1) What's wrong with…
kramer65
  • 50,427
  • 120
  • 308
  • 488
34
votes
1 answer

Use of enable_shared_from_this with multiple inheritance

BI am using enable_shared_from_this in my code, and I am not sure if its usage is correct. This is the code: class A: public std::enable_shared_from_this { public: void foo1() { auto ptr = shared_from_this(); } }; class…
33
votes
1 answer

Any way to inherit from same generic interface twice (with separate types) in Kotlin?

I have a scenario in my code where I would like a class to implement an interface for two separate types, like this example: interface Speaker { fun talk(value: T) } class Multilinguist : Speaker, Speaker { override fun…
Merrillogic
  • 945
  • 1
  • 9
  • 13
32
votes
2 answers

Multiple inheritance workarounds

I'm trying to discover a pattern for combining multiple interfaces into one abstract class. Presently I can combine multiple interfaces via implements, but an interface cannot declare a constructor. When I must introduce a constructor I'm forced…
Corey Alix
  • 2,694
  • 2
  • 27
  • 38
31
votes
4 answers

Sqlalchemy: avoiding multiple inheritance and having abstract base class

So I have a bunch of tables using SQLAlchemy that are modelled as objects which inherit from the result to a call to declarative_base(). Ie: Base = declarative_base() class Table1(Base): # __tablename__ & such here class Table2(Base): #…
Adam Parkin
  • 17,891
  • 17
  • 66
  • 87
31
votes
2 answers

In C++, should I almost always use virtual inheritance?

I see from this entry that virtual inheritance adds sizeof(pointer) to an object's memory footprint. Other than that, are there any drawbacks to me just using virtual inheritance by default, and conventional inheritance only when needed? It seems…
SuperElectric
  • 17,548
  • 10
  • 52
  • 69
31
votes
2 answers

C++ multiple inheritance order

I'm trying to understand the affect of inheritance order in C++.. I looked online, but I couldn't find a clear and sufficient answer... So, for the sake of the question, assume there are 2 classes: class B and class C. Now, define: class A1 : public…
TCS
  • 5,790
  • 5
  • 54
  • 86
31
votes
5 answers

Multiple inheritance on Java interfaces

I thought multiple inheritance was always illegal in Java, but this code compiles: public interface A { void a(); } public interface B { void b(); } public interface AB extends A, B { } Would having an empty interface such as AB be considered…
Jacob Wallace
  • 887
  • 2
  • 12
  • 24