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
66
votes
17 answers

Does C# support multiple inheritance?

A colleague and I are having a bit of an argument over multiple inheritance. I'm saying it's not supported and he's saying it is. So, I thought that I'd ask the brainy bunch on the net.
Neil Knight
  • 47,437
  • 25
  • 129
  • 188
65
votes
5 answers

Inherit interfaces which share a method name

There are two base classes have same function name. I want to inherit both of them, and over ride each method differently. How can I do that with separate declaration and definition (instead of defining in the class definition)? #include…
Gohan
  • 2,422
  • 2
  • 26
  • 45
64
votes
3 answers

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

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…
Name McChange
  • 2,750
  • 5
  • 27
  • 46
62
votes
1 answer

GCC can't differentiate between operator++() and operator++(int)

template struct Pre { CRTP & operator++(); }; template struct Post { CRTP operator++(int); }; struct Derived : Pre , Post {}; int main() { Derived d; d++; ++d; } I get…
jotik
  • 17,044
  • 13
  • 58
  • 123
58
votes
5 answers

How does Python's "super" do the right thing?

I'm running Python 2.5, so this question may not apply to Python 3. When you make a diamond class hierarchy using multiple inheritance and create an object of the derived-most class, Python does the Right Thing (TM). It calls the constructor for the…
Joseph Garvin
  • 20,727
  • 18
  • 94
  • 165
56
votes
10 answers

How can interfaces replace the need for multiple inheritance when have existing classes

First of all... Sorry for this post. I know that there are many many posts on stackoverflow which are discussing multiple inheritance. But I already know that Java does not support multiple inheritance and I know that using interfaces should be an…
fpdragon
  • 1,867
  • 4
  • 25
  • 36
54
votes
34 answers

Should C# have multiple inheritance?

I have come across numerous arguments against the inclusion of multiple inheritance in C#, some of which include (philosophical arguments aside): Multiple inheritance is too complicated and often ambiguous It is unnecessary because interfaces…
Richard Dorman
  • 23,170
  • 16
  • 45
  • 49
54
votes
1 answer

How can I require a method argument in Java to implement multiple interfaces?

It's legal to do this in Java: void spew(Appendable x) { x.append("Bleah!\n"); } How can I do this (syntax not legal): void spew(Appendable & Closeable x) { x.append("Bleah!\n"); if (timeToClose()) x.close(); } I…
Jason S
  • 184,598
  • 164
  • 608
  • 970
52
votes
3 answers

Why do multiple-inherited functions with same name but different signatures not get treated as overloaded functions?

The following snippet produces an "ambigious call to foo" error during compilation, and I'd like to know if there is any way around this problem without fully qualifying the call to foo: #include struct Base1{ void foo(int){ …
Xeo
  • 129,499
  • 52
  • 291
  • 397
50
votes
4 answers

C# extension method as an interface implementation

I was wondering if a C# extension method of some class could act as an implementation of interface? What do I have: An iterface: public interface IEventHandler { void Notify(SEvent ev, IEventEmmiter source); } A class that implements it: class…
PJK
  • 2,082
  • 3
  • 17
  • 28
48
votes
5 answers

Is super() broken in Python-2.x?

It's often stated that super should be avoided in Python 2. I've found in my use of super in Python 2 that it never acts the way I expect unless I provide all arguments such as the example: super(ThisClass, self).some_func(*args, **kwargs) It seems…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
47
votes
3 answers

C++ multiple inheritance function call ambiguity

I have a basic question related to multiple inheritance in C++. If I have a code as shown below: struct base1 { void start() { cout << "Inside base1"; } }; struct base2 { void start() { cout << "Inside base2"; } }; struct derived : base1,…
goldenmean
  • 18,376
  • 54
  • 154
  • 211
45
votes
4 answers

How did C#'s lack of multiple inheritance lead to the need for interfaces?

In The C# Programming Language Krzysztof Cwalina states in an annotation: we explicitly decided not to add support for multiple inheritance [...] the lack of multiple inheritance forced us to add the concept of interfaces, which in turn are…
P.Brian.Mackey
  • 43,228
  • 68
  • 238
  • 348
44
votes
4 answers

How to reference a generic return type with multiple bounds

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…
Rafael T
  • 15,401
  • 15
  • 83
  • 144
43
votes
2 answers

Typescript multiple inheritance

I'm need of multiple inheritance in typescript. Logically it is not good to put a lot of functionality to hierarchy. I have one base class and number of hierarchy branches. But I need somehow to use mixings to put some main logic in separate…
Vayrex
  • 1,417
  • 1
  • 11
  • 13