473,498 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about two interfaces derived from the same one.

Roy
If I have two interfaces derived from the same one. How do I implement the
methods in my class supporting both interfaces? I would like to have
different implementation for methods in base interface from different
interfaces.
Feb 17 '06 #1
3 1260
Hello, Roy!

R> If I have two interfaces derived from the same one. How do I implement
R> the methods in my class supporting both interfaces? I would like to have
R> different implementation for methods in base interface from different
R> interfaces

Here is code sample

interface IBase
{
void method();
}

interface IDerived1 : IBase
{
void method();
}

interface IDerived2 : IBase
{
void method();
}

class Implementor : IDerived1, IDerived2
{
void IDerived1.method()
{ }

void IDerived2.method()
{ }
}
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Feb 17 '06 #2
Roy
Vadym,
I got the following 3 compile errors:
'IDerived1.p' in explicit interface declaration is not a member of interface
'IDerived2.p' in explicit interface declaration is not a member of interface
'Implementor' does not implement interface member 'IBase.p'

Where p is a property defined in IBase.

Why?

Thanks.
"Vadym Stetsyak" wrote:
Hello, Roy!

R> If I have two interfaces derived from the same one. How do I implement
R> the methods in my class supporting both interfaces? I would like to have
R> different implementation for methods in base interface from different
R> interfaces

Here is code sample

interface IBase
{
void method();
}

interface IDerived1 : IBase
{
void method();
}

interface IDerived2 : IBase
{
void method();
}

class Implementor : IDerived1, IDerived2
{
void IDerived1.method()
{ }

void IDerived2.method()
{ }
}
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot

Feb 17 '06 #3
Roy <Ro*@discussions.microsoft.com> wrote:
I got the following 3 compile errors:
'IDerived1.p' in explicit interface declaration is not a member of interface
'IDerived2.p' in explicit interface declaration is not a member of interface
'Implementor' does not implement interface member 'IBase.p'

Where p is a property defined in IBase.

Why?


From the C# spec:

<quote>
The fully qualified name of an interface member must reference the
interface in which the member was declared.
</quote>

p was *declared* in IBase, not IDerived1 or IDerived2.

--
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 17 '06 #4

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

Similar topics

8
3194
by: Shawn Casey | last post by:
Consider the following code: interface IBase { virtual void BaseFunction() = 0; }; interface IDerived : public IBase { virtual void DerivedFunction() = 0;
8
2426
by: Shaun C Farrugia | last post by:
I have a multi team solution being built where teams are segmented off into seperate projects. One project is an over all framework containing a Broker class responsible for instantiating...
17
2328
by: Picho | last post by:
Hi all, I popped up this question a while ago, and I thought it was worth checking again now... (maybe something has changed or something will change). I read this book about component...
14
339
by: Daniel Billingsley | last post by:
Can someone please comment if there's something wrong from an OO point of view with the model represented by the following code snippet. I hope it's fairly obvious what the point is of the code I...
7
1569
by: Ant | last post by:
Hi, I’m wondering what practical use is there for creating interfaces. I can fully appreciate creating an abstract class for the purpose of inheriting, but why an interface? Is it just to...
9
5177
by: Sean Kirkpatrick | last post by:
To my eye, there doesn't seem to be a whole lot of difference between the two of them from a functional point of view. Can someone give me a good explanation of why one vs the other? Sean
8
1439
by: ^MisterJingo^ | last post by:
Hi all, I have a question regarding inheritance. I'll use the following code for an example (its been stripped down to the minimum): // code start using System; class Animal {
7
4452
by: jason | last post by:
In the microsoft starter kit Time Tracker application, the data access layer code consist of three cs files. DataAccessHelper.cs DataAcess.cs SQLDataAccessLayer.cs DataAcccessHelper appears...
1
1707
by: Larry | last post by:
I checked definition of class CollectionBase public abstract class CollectionBase : IList, ICollection, IEnumerable, it implements 3 interface IList, ICollection and IEnumerable. I found...
0
7165
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,...
0
7379
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...
0
5462
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4910
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1419
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
291
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.