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
30
votes
2 answers

using declaration in variadic template

This question is inspired in the following solution to multiple inheritance overloading pseudo-ambiguity, which is a nice way to implement lambda visitors for boost::variant as proposed in this answer: I want to do something like the…
lurscher
  • 25,930
  • 29
  • 122
  • 185
29
votes
3 answers

Mixing virtual and non-virtual inheritance of a base class

This is the code: struct Biology { Biology() { cout << "Biology CTOR" << endl; } }; struct Human : Biology { Human() { cout << "Human CTOR" << endl; } }; struct Animal : virtual Biology { Animal() { cout << "Animal CTOR" <<…
29
votes
2 answers

Multiple inheritance metaclass conflict

I need a double inheritance for a class. I tried several syntaxes but I don't understand the concept of metaclass. from PyQt5.QtGui import QStandardItem from configparser import ConfigParser class FinalClass(ConfigParser, QStandardItem): def…
Mauricio
  • 670
  • 1
  • 8
  • 23
29
votes
5 answers

Multiple Inheritance from two derived classes

I have an abstract base class which acts as an interface. I have two "sets" of derived classes, which implement half of the abstract class. ( one "set" defines the abstract virtual methods related to initialization, the other "set" defines those…
mmocny
  • 8,775
  • 7
  • 40
  • 50
28
votes
3 answers

Why is this an ambiguous MRO?

class First(object): def __init__(self): print("first") class Second(First): def __init__(self): print("second") class Third(First, Second): def __init__(self): print("third") Source Why can't Python create a…
Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247
28
votes
7 answers

When virtual inheritance IS a good design?

EDIT3: Please be sure to clearly understand what I am asking before answering (there are EDIT2 and lots of comments around). There are (or were) many answers which clearly show misunderstanding of the question (I know that's also my fault, sorry for…
Roman L
  • 3,006
  • 25
  • 37
28
votes
1 answer

How to avoid infinite recursion with super()?

I have code like this: class A(object): def __init__(self): self.a = 1 class B(A): def __init__(self): self.b = 2 super(self.__class__, self).__init__() class C(B): def __init__(self): self.c = 3 …
david4dev
  • 4,854
  • 2
  • 28
  • 35
28
votes
6 answers

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

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…
Roshan Jha
  • 2,091
  • 1
  • 21
  • 30
28
votes
6 answers

PHP trait method conflicts: trait "inheritance" and trait hierarchies

UPDATE: I am not alone in my pondering on this issue and it seems it is indeed a bug. See here. The day it is fixed is going to be a fantastic day! :) This started out as I love PHP traits! I'm going to use them everywhere! ^_^ and now it has…
user651390
26
votes
5 answers

Multiple Inheritance, C++ and Same Method Signature in Multiple Super Classes

I have no experience in C++, and I come from a Java background. Lately, I was asked in an interview on why Java would not allow multiple inheritence and the answer was pretty easy. However, I am still curious on how C++ deals with that since it…
Sam
  • 2,398
  • 4
  • 25
  • 37
26
votes
1 answer

python typing module: Mixin

Is there any class under typing that behaves like a mixin? For example from typing import Union class A: pass class B: pass class C: pass class D(A, B, C): pass # current: ab is A or B, but not both def f(ab: Union[A, B]): pass #…
András Gyömrey
  • 1,770
  • 1
  • 15
  • 36
26
votes
1 answer

Usage of multiple inheritance in Java 8

Am I using a feature of Java 8 or misusing it? Refer the code and explanation below to know as to why it was chosen to be like this. public interface Drawable { public void compileProgram(); public Program getProgram(); default public…
skiwi
  • 66,971
  • 31
  • 131
  • 216
26
votes
5 answers

C++ inherit from multiple base classes with the same virtual function name

I tried this code: class A { virtual void foo() = 0; }; class B { virtual void foo() = 0; }; class C : public A, public B { //virtual void A::foo(){} //virtual void B::foo(){} virtual void A::foo(); virtual void…
watson
  • 395
  • 1
  • 5
  • 14
25
votes
3 answers

Overload resolution for multiply inherited operator()

First, consider this C++ code: #include struct foo_int { void print(int x) { printf("int %d\n", x); } }; struct foo_str { void print(const char* x) { printf("str %s\n", x); } }; struct foo :…
25
votes
2 answers

'Inaccessible direct base' caused by multiple inheritance

Spoiler alert: Maybe a stupid question. :) #include using namespace std; class Base { public: virtual void YourMethod(int) const = 0; }; class Intermediate : private Base { public: virtual void YourMethod(int i)…
nakiya
  • 14,063
  • 21
  • 79
  • 118