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

Ambiguous Overloads

Hi all,
If I have the following methods:

public void foo(object o)
{
}

public void foo(string s)
{
}

public void foo(array a)
{
}

And I call:
foo(null);

I should (and do) get an ambiguous call error.

But if I comment out the foo(string) or foo(array)

then I do not get the error and it just goes to the not foo(object) one
(ie foo(array)).

Why is this?

JB
Feb 23 '06 #1
2 1345
Maybe this can help you.

http://msdn.microsoft.com/library/de...ec_7_4_2_2.asp

Feb 23 '06 #2
John B <jb******@yahoo.com> wrote:
If I have the following methods:

public void foo(object o)
{
}

public void foo(string s)
{
}

public void foo(array a)
{
}

And I call:
foo(null);

I should (and do) get an ambiguous call error.

But if I comment out the foo(string) or foo(array)

then I do not get the error and it just goes to the not foo(object) one
(ie foo(array)).

Why is this?


Because it picks the most specific one. Array and string aren't more or
less specific than each other, so there's ambiguity - but string is
unambiguously more specific than object (as is Array).

--
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 23 '06 #3

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

Similar topics

7
by: John M | last post by:
Can someone tell how to fix my visual c++ so it can discard this error message. I get this error message error C2593: 'operator >>' is ambiguous But I do not when I am on my mandrake linux...
4
by: rjd | last post by:
Does anybody else see this in VS.NET 2003? When I get a genuine C++ compiler error (could be anything, usually innocuous) it's regularly followed by a slew of these spurious and completely...
0
by: Michi Henning | last post by:
Hi, the following code produces an error on the second-last line: Interface Left Sub op() End Interface Interface Right Sub op(ByVal i As Integer)
9
by: Prasad | last post by:
HI, I am a beginner in VC++.. I am trying to write a Win32 console application in visual studio.. I am using following header files.. #include <STRING> using namespace std; #include...
4
by: Gary Brown | last post by:
Hi, Why are fn(object parameters) and fn(params object parameters)
4
by: Chameleon | last post by:
Can anyone explain me why the code below produce (with mingw-g++) the following error message: --------------------------------------------------------------- main10.cpp: In function `int main()':...
9
by: neildferguson | last post by:
I am using templates with a little project I am working on. My compiler (GCC) is finding a particular construct ambiguous. Can anyone suggest something I might change in the declaration of class...
3
by: i3x171um | last post by:
To start off, I'm using GCC4. Specifically, the MingW (setjmp/longjmp) build of GCC 4.2.1 on Windows XP x64. I'm writing a class that abstracts a message, which can be either an integer (stored as...
8
by: Anna Smidt | last post by:
lf.lfHeight = - (int) (fabs (pt.y) / 10.0 + 0.5) ; Error 1 error C2668: 'fabs' : ambiguous call to overloaded function ezfont.cpp 47 stasm I first thought that the compiler wants to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.