473,406 Members | 2,956 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,406 software developers and data experts.

C# method overloading in implemented interfaces?

Hi everyone,

I'm having an interesting problem where it seems that method overloads
are not being handled properly in interfaces. Consider the following
code:

interface Foo
{
void f();
void f(int x);
}

When a class is created that implements Foo, the following results:

class SpecialFoo : Foo
{
#region Foo Members

public void f()
{
// TODO: Add SpecialFoo.f implementation
}

void NS.Foo.f(int x)
{
// TODO: Add SpecialFoo.NS.Foo.f implementation
}

#endregion
}

(where NS is the namespace where Foo and SpecialFoo reside).

Is this a bug or simply a language feature that I'm not aware of?
Thanks,
-calvin

Nov 16 '05 #1
5 6978
I'm having an interesting problem where it seems that method overloads
are not being handled properly in interfaces.


What is the problem? The code you posted compiles fine here.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2
>I'm having an interesting problem where it seems that method overloads
are not being handled properly in interfaces.


It looks like you posted the "starter" code that Visual Studio will add for
you if you ask it to. I guess VS uses a simple algorithm - implement the
first version of "f" implicitly but the second one explicitly.

I agree this might seem like an odd algorithm, but it is just stub code that
we can change if needed. VS 2005 gives you the choice of how the stub code
should look (implicit or explicit).
Nov 16 '05 #3
Interfaces do no contain code, the classes that implement the interfaces
need to implement the methods and properties that are defined in the
interface. Not sure what you used to code the class (VS 2005?), but the code
itself looks good to me.

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
<ca*********@sentiment.cjb.net> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hi everyone,

I'm having an interesting problem where it seems that method overloads
are not being handled properly in interfaces. Consider the following
code:

interface Foo
{
void f();
void f(int x);
}

When a class is created that implements Foo, the following results:

class SpecialFoo : Foo
{
#region Foo Members

public void f()
{
// TODO: Add SpecialFoo.f implementation
}

void NS.Foo.f(int x)
{
// TODO: Add SpecialFoo.NS.Foo.f implementation
}

#endregion
}

(where NS is the namespace where Foo and SpecialFoo reside).

Is this a bug or simply a language feature that I'm not aware of?
Thanks,
-calvin

Nov 16 '05 #4
> Not sure what you used to code the class (VS 2005?), but the code
itself looks good to me.


It looks to be the VS 2003 stub code. VS 2005 is different.
Nov 16 '05 #5
Hi folks,

Thanks for the feedback. Yes, it's VS 2003 stub code. The problem is
that I expected:

class SpecialFoo : Foo
{
#region Foo Members
public void f()
{
}

public void f(int x)
{
}
#endregion
}

rather than

void NS.Foo.f(int x)

for the overloaded version of f taking the integer argument.

I assume VS 2005 returns the stub code that I expected?

Thanks,
-calvin
MarkT wrote:
Not sure what you used to code the class (VS 2005?), but the code
itself looks good to me.


It looks to be the VS 2003 stub code. VS 2005 is different.


Nov 16 '05 #6

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

Similar topics

39
by: zeus | last post by:
I know function overloading is not supported in C. I have a few questions about this: 1. Why? is it from technical reasons? if so, which? 2. why wasn't it introduced to the ANSI? 3. Is there any...
18
by: Daniel Gustafsson | last post by:
Hi there, hmm, I've just started with C# and I'm experimenting with method overloading. It seems like it's not possible to override method using return types, only parameters. Is that by design,...
1
by: Abdessamad Belangour | last post by:
Hi all, the GetInterfaces() method of the Type class, brings all the interfaces implemented by a Class. The problem is that the method brings also all the interfaces implemented by it base type....
7
by: Christopher Wells | last post by:
There's something I don't understand about how the CollectionBase class is defined. I can declare: class Derived : CollectionBase { } I can instantiate this Derived class: Derived derived...
3
by: bauscharln | last post by:
hoi, I just wanted to add a static method to my interface, but that's not allowed! Is there a reason for this??? (Yes, I could make an abstract base class, but that's not what I want, since I...
13
by: CJ Taylor | last post by:
Alright on a DataRow you have the BeginEdit method Where can I catch an event that tells me that method is being fired or does one exist? Thanks, -CJ
2
by: Christophe | last post by:
class A {} class B {} interface MyInterface { void method(A a); void method(B b); }
2
by: Tobias Erbsland | last post by:
Hello I'm not really sure if this should be possible according to the standard, because didn't found anything in the FAQ and in the C++ book about that. ==== example === class A { public:
3
by: Chameleon | last post by:
What is better if you want upcasting in intermediate classes like below? Multiple Inheritance and Overloading or simply RTTI? RTTI wants time but MI and Overloading create big objects (because of...
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
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
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
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
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,...
0
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...

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.