473,394 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Why Doesn't c# support Multiple Inheritance ?

There are a number of reasons we don't implement Multiple Implementation
Inheritance directly. (As you know, we support Multiple Interface
Inheritance).

However, I should point out that it's possible for compilers to create MI
for their types inside the CLR. There are a few rough edges if you go down
this path: the result is unverifiable, there is no interop with other
languages via the CLS, and in V1 and V1.1 you may run into deadlocks with the
OS loader lock. (We're fixing that last problem, but the first two problems
remain). The technique is to generate some VTables in RVA-based static
fields. In order to deposit the addresses of managed methods (which probably
haven't been JITted yet), you use the VTFixup construct. This construct is a
table of triplets. The triplets consist of a token to a managed method, an
address in your image that should be fixed up (in this case, a slot of the
VTable you are creating in the RVA-based static), and some flags. The
possible flags are described in corhdr.h and they allow you to specify 32-
vs. 64-bit pointer sizes, control over virtual behavior, and whether some
reverse-PInvoke behavior should be applied in the form of a thunk that
eventually dispatches to the managed method. If we are performing an
unmanaged->managed transition, you also have some control over which
AppDomain should be selected for us to dispatch the call. However, one of
these options (COR_VTABLE_FROM_UNMANAGED_RETAIN_APPDOMAIN) doesn't exist in
V1. We added it in V1.1.

There are several reasons we haven't provided a baked-in, verifiable,
CLS-compliant version of multiple implementation inheritance:

1. Different languages actually have different expectations for how MI
works. For example, how conflicts are resolved and whether duplicate bases
are merged or redundant. Before we can implement MI in the CLR, we have to do
a survey of all the languages, figure out the common concepts, and decide how
to express them in a language-neutral manner. We would also have to decide
whether MI belongs in the CLS and what this would mean for languages that
don't want this concept (presumably VB.NET, for example). Of course, that's
the business we are in as a common language runtime, but we haven't got
around to doing it for MI yet.

2. The number of places where MI is truly appropriate is actually quite
small. In many cases, multiple interface inheritance can get the job done
instead. In other cases, you may be able to use encapsulation and delegation.
If we were to add a slightly different construct, like mixins, would that
actually be more powerful?

3. Multiple implementation inheritance injects a lot of complexity into the
implementation. This complexity impacts casting, layout, dispatch, field
access, serialization, identity comparisons, verifiability, reflection,
generics, and probably lots of other places.

It's not at all clear that this feature would pay for itself. It's something
we are often asked about. It's something we haven't done due diligence on.
But my gut tells me that, after we've done a deep examination, we'll still
decide to leave the feature unimplemented.
--
please post your doubts and help me to explore ny knowledge.
Feb 15 '06 #1
1 2944
vinoraja <vi******@discussions.microsoft.com> wrote:

<snip>

Note that this post was taken verbatim from a post made by Chris
Brumme. It's available in the C# FAQ at

http://blogs.msdn.com/csharpfaq/arch.../07/85562.aspx

and was also at

http://dotnetjunkies.com/WebLog/unkn...2003/09/04/140
1.aspx
It's always good to include attributions rather than passing off an
answer as your own...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 15 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Graham Banks | last post by:
Does using multiple inheritance introduce any more performance overhead than single inheritance?
5
by: Morgan Cheng | last post by:
It seems no pattern defined by GoF takes advantage of multiple inheritance. I am wondering if there is a situation where multiple inheritance is a necessary solution. When coding in C++, should...
20
by: km | last post by:
Hi all, In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent class D with all the attributes of its base classes. how do i do that ? thanks in...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
8
by: mmu2643 | last post by:
Hi, I had a question regarding multiple inheritance. class B1{ public: int a; };
60
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the...
15
by: iKiLL | last post by:
hi all, I would like to be able to create an umbrella class for all my main global sections but I would still like to keep them all in separate file something like the below but I keep getting...
7
by: Adam Nielsen | last post by:
Hi everyone, I'm having some trouble getting the correct chain of constructors to be called when creating an object at the bottom of a hierarchy. Have a look at the code below - the inheritance...
2
by: Paul McGuire | last post by:
On May 25, 8:37 am, Michael Hines <michael.hi...@yale.eduwrote: Here's a more general version of your testing code, to detect *any* diamond multiple inheritance (using your sample classes). --...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.