Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7048007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:50:23+00:00 2026-05-28T02:50:23+00:00

When compiling void ambig( signed long) { } void ambig(unsigned long) { } int

  • 0

When compiling

void ambig(  signed long) { }
void ambig(unsigned long) { }

int main(void) { ambig(-1); return 0; }

I get

error C2668: 'ambig' : ambiguous call to overloaded function
    could be 'void ambig(unsigned long)'
    or 'void ambig(long)'
while trying to match the argument list '(int)'

I know I can ‘fix’ it by saying -1L instead of -1, but why/how exactly is this considered ambiguous in the first place?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:50:24+00:00Added an answer on May 28, 2026 at 2:50 am

    You’re passing an int to this overloaded function.

    Although human intuition says that ambig(signed long) ought to be preferred because your input is a negative integer (which cannot be represented as such by an unsigned long), the two conversions are in fact equivalent in “precedence” in C++.

    That is, the conversion int → unsigned long is considered to be just as valid as int → signed long, and neither is preferred to the other.

    On the other hand, if your parameter were already a long rather than an int, then there is an exact match to signed long, with no conversion necessary. This avoids the ambiguity.

    void ambig(  signed long) { }
    void ambig(unsigned long) { }
    
    int main(void) { ambig(static_cast<long>(-1)); return 0; }
    

    “Just one of those things”.


    [C++11: 4.13/1]: (“Integer conversion rank”)

    Every integer type has an integer conversion rank defined as follows:

    • [..]
    • The rank of a signed integer type shall be greater than the rank of any signed integer type with a smaller size.
    • The rank of long long int shall be greater than the rank of long int, which shall be greater than the rank of int, which shall be greater than the rank of short int, which shall be greater than the rank of signed char.
    • The rank of any unsigned integer type shall equal the rank of the corresponding signed integer type.
    • [..]

    [ Note: The integer conversion rank is used in the definition of the integral promotions (4.5) and the usual arithmetic conversions (Clause 5). —end note ]

    Overload resolution is complex, and is defined in [C++11: 13.3]; I shan’t bore you by quoting a majority of it here.

    Here’s a highlight, though:

    [C++11: 13.3.3.1/8]: If no conversions are required to match an argument to a parameter type, the implicit conversion sequence is the standard conversion sequence consisting of the identity conversion (13.3.3.1.1).

    [C++11: 13.3.3.1/9]: If no sequence of conversions can be found to convert an argument to a parameter type or the conversion is otherwise ill-formed, an implicit conversion sequence cannot be formed.

    [C++11: 13.3.3.1/10]: If several different sequences of conversions exist that each convert the argument to the parameter type, the implicit conversion sequence associated with the parameter is defined to be the unique conversion sequence designated the ambiguous conversion sequence. For the purpose of ranking implicit conversion sequences as described in 13.3.3.2, the ambiguous conversion sequence is treated as a user-defined sequence that is indistinguishable from any other user-defined conversion sequence134. If a function that uses the ambiguous conversion sequence is selected as the best viable function, the call will be ill-formed because the conversion of one of the arguments in the call is ambiguous.

    • /10 is the case you’re experiencing; /8 is the case you use with a long argument.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

while compiling the following code i have got error @Override public void routeCustomerRequest (int
Problem Why would compiling a program which has an int main(void) main function differ
Compiling the following code will return The call is ambiguous between the following methods
When compiling the following code: void DoSomething(int Numbers[]) { int SomeArray[] = Numbers; }
So... I'm compiling into assembler, with gcc -S -O2 -m32: void h(int y){int x;
Compiling this lines long int sz; char tmpret[128]; //take substring of c, translate in
While compiling on GCC I get the error: pure-specifier on function-definition , but not
I have the following code: int main(void) { struct { int x; } a,
public static void main(String args[]) { int[] intarray = {1, 3, 6, 8, 2,
I'm compiling a trivial C++ file Temp.cpp : #include <string> int main() { std::wstring

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.