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

alternative to multiple inheritance in c++

Suppose i have two classes A and B:

class A
{

public method_a();

}

class B
{

public method_b();
}

if i want to have multiple inheritance in c# like C++ so i can have
access to both methods:

class C : public A,B
{

public method_c();
}

HOw can i achive that in c#?

Mar 4 '07 #1
2 2682
weird0 <am********@gmail.comwrote:
Suppose i have two classes A and B:

class A
{

public method_a();

}

class B
{

public method_b();
}

if i want to have multiple inheritance in c# like C++ so i can have
access to both methods:

class C : public A,B
{

public method_c();
}

HOw can i achive that in c#?
You just can't. In general, prefer composition to inheritance - so
class C would have an instance of A and an instance of B as member
variables.

Note that although .NET has no multiple inheritance of implementation,
you can implement multiple interfaces.

--
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
Mar 4 '07 #2
On Mar 4, 4:01 pm, "weird0" <amiredi...@gmail.comwrote:
Suppose i have two classes A and B:

class A
{

public method_a();

}

class B
{

public method_b();

}

if i want to have multiple inheritance in c# like C++ so i can have
access to both methods:

class C : public A,B
{

public method_c();

}

HOw can i achive that in c#?
I would recommend changing A & B both into interfaces IA and IB. Or
you may also let B inherit A and let C inherit B.

Freiddy
http://fei.yuanbw.googlepages.com/

Mar 4 '07 #3

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?
62
by: christopher diggins | last post by:
Since nobody responded to my earlier post , I thought I would try to explain what I am doing a bit differently. When multiply inheriting pure virtual (abstract) base classes, a class obviously...
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...
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: **Developer** | last post by:
I have a control called MyPanel that inherits from Panel. Also a control called MyRTB that inherits from RichTextBox. They are used on a form as follows: MyPanel in on the form and MyRTF is...
47
by: Mark | last post by:
why doesn't .NET support multiple inheritance? I think it's so silly! Cheers, Mark
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...
47
by: Larry Smith | last post by:
I just read a blurb in MSDN under the C++ "ref" keyword which states that: "Under the CLR object model, only public single inheritance is supported". Does this mean that no .NET class can ever...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.