473,386 Members | 1,791 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,386 software developers and data experts.

How come c# don't allow multiple inheritance?

Hi,

How come that a programming language not yet 10years old dosen't support
Multiple inherritances?, I got 2 classes, both with alot of fields and
methods that i need from my third class, so i tried:

class myClass3 : myClass1, myClass2 {

and got an error says that i cant. How can C# be a compete with C++ if
you cant even make a simple thing like that?
Is there a work around?

Patrick

*** Sent via Developersdex http://www.developersdex.com ***
May 23 '06 #1
10 3176
"Patrick F" <da**@pafo.net> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
How come that a programming language not yet 10years old dosen't support
Multiple inherritances?
This question comes up regularly...
http://www.google.com/search?sourcei...inheritance%22

See also: http://blogs.msdn.com/csharpfaq/arch.../07/85562.aspx
straight from the horse's mouth, as it were...
Is there a work around?


Multiple Interface Inheritance
May 23 '06 #2
Interfaces from what i have seen cant contain Fields, and both my
classes that i am using contains fields. I have it like this (just for
demonstration):

A - Car class (alot of fields for data)
AC - Array of A (field) that is dynamic so i can add and remove Array
elements (like a que/stack), alot of methods for extracting data from A

B - Bus class (alot of fields for data)
BC - Array of B (field) that is dynamic so i can add and remove Array
elements (like a que/stack), , alot of methods for extracting data from
B

C - Traffic class, witch needs both AC and BC classes, then from C i
have methods to eg. count the number of cars in A and edit one bus in
the middle of the bus array in BC.

Program D - Array of C (multiple trafic scenarios), D should be able to
loop thru all Traffic Classes in C and get the count of Cars from Class
AC

This would be very simple to do if multiple inherritance were allowed:
class C : AC, BC {}

ClassC[] D = new ClassC[5];

D[0].ACountCars or D[1].BEditBus(5).Passangers = 10

When i try to use interface in class BC i get the following error:
Error 1 Interfaces cannot contain fields

The interface BC can not handle the Array of B objects.

How do you get around this?

Patrick

*** Sent via Developersdex http://www.developersdex.com ***
May 23 '06 #3
C# supports multiple inheritance thru interfaces. Multiple inheritance thru
classes is not supported.

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------

"Patrick F" <da**@pafo.net> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Hi,

How come that a programming language not yet 10years old dosen't support
Multiple inherritances?, I got 2 classes, both with alot of fields and
methods that i need from my third class, so i tried:

class myClass3 : myClass1, myClass2 {

and got an error says that i cant. How can C# be a compete with C++ if
you cant even make a simple thing like that?
Is there a work around?

Patrick

*** Sent via Developersdex http://www.developersdex.com ***

May 23 '06 #4
OMG, this topic comes every month...

"Patrick F" <da**@pafo.net> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Hi,

How come that a programming language not yet 10years old dosen't support
Multiple inherritances?, I got 2 classes, both with alot of fields and
methods that i need from my third class, so i tried:

class myClass3 : myClass1, myClass2 {

and got an error says that i cant. How can C# be a compete with C++ if
you cant even make a simple thing like that?
Is there a work around?

Patrick

*** Sent via Developersdex http://www.developersdex.com ***

May 23 '06 #5
It has single inheritance plus interfaces.
C# basically just copied java.

May 23 '06 #6
It sounds like A and B should be inheriting from C instead of the other way
around. Then you could treat all cars and buses exactly the same except
where it really matters.

--
Jeffrey Hornby
Hornby Consulting, Inc.

"Patrick F" wrote:
Interfaces from what i have seen cant contain Fields, and both my
classes that i am using contains fields. I have it like this (just for
demonstration):

A - Car class (alot of fields for data)
AC - Array of A (field) that is dynamic so i can add and remove Array
elements (like a que/stack), alot of methods for extracting data from A

B - Bus class (alot of fields for data)
BC - Array of B (field) that is dynamic so i can add and remove Array
elements (like a que/stack), , alot of methods for extracting data from
B

C - Traffic class, witch needs both AC and BC classes, then from C i
have methods to eg. count the number of cars in A and edit one bus in
the middle of the bus array in BC.

Program D - Array of C (multiple trafic scenarios), D should be able to
loop thru all Traffic Classes in C and get the count of Cars from Class
AC

This would be very simple to do if multiple inherritance were allowed:
class C : AC, BC {}

ClassC[] D = new ClassC[5];

D[0].ACountCars or D[1].BEditBus(5).Passangers = 10

When i try to use interface in class BC i get the following error:
Error 1 Interfaces cannot contain fields

The interface BC can not handle the Array of B objects.

How do you get around this?

Patrick

*** Sent via Developersdex http://www.developersdex.com ***

May 23 '06 #7
"Doug H" <do****@gmail.com> wrote:
It has single inheritance plus interfaces.
C# basically just copied java.


And Delphi, and Objective-C, and Modula-3, and CLU. I would venture that
multiple inheritance is rarer than single inheritance.

-- Barry

--
http://barrkel.blogspot.com/
May 24 '06 #8
"Barry Kelly" <ba***********@gmail.com> wrote in message
news:nq********************************@4ax.com...
It has single inheritance plus interfaces.
C# basically just copied java.
And Delphi, and Objective-C, and Modula-3, and CLU.


And Smalltalk.
I would venture that multiple inheritance is rarer than single
inheritance.


In the world of programming languages. In the real world, however, MI is
quite common. :)

///ark
May 24 '06 #9
"Mark Wilden" <Ma********@newsgroups.nospam> wrote:
In the world of programming languages. In the real world, however, MI is
quite common. :)


Are you sure? I would guess that single-celled organisms outnumber more
complex organisms by a substantial margin.

:)

-- Barry

--
http://barrkel.blogspot.com/
May 24 '06 #10
"Barry Kelly" <ba***********@gmail.com> wrote in message
news:ju********************************@4ax.com...
"Mark Wilden" <Ma********@newsgroups.nospam> wrote:
In the world of programming languages. In the real world, however, MI is
quite common. :)


Are you sure? I would guess that single-celled organisms outnumber more
complex organisms by a substantial margin.


My species bias is showing. :)
May 24 '06 #11

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...
30
by: Vla | last post by:
why did the designers of c++ think it would be more useful than it turned out to be?
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...
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...
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...
21
by: raylopez99 | last post by:
Well, contrary to the implication in my 2000 textbook on C# (public beta version), C# does allow multiple inheritance, so long as it's serially chained as follows: class derived02 : derived01 {...
3
by: johanatan | last post by:
When I first heard about these new features, I was very excited as it would have (if implemented as I had expected) rendered mimicking multiple inheritance almost painless in C#. Unfortunately,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.