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 8354565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:35:01+00:00 2026-06-09T09:35:01+00:00

Why are the following overloaded function calls ambiguous?? With the compile error: call of

  • 0

Why are the following overloaded function calls ambiguous?? With the compile error:

call of overloaded ‘test(long int)’ is ambiguous,candidates are: void test(A)|
void test(B)|

The code:

class A
{
    public:
        A(int){}
        A(){}
};

class B: public A
{
    public:
        B(long){}
        B(){}
};

void test(A a)
{
}

void test(B b)
{
}

void main()
{
    test(0L);
    return;
}
  • 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-06-09T09:35:02+00:00Added an answer on June 9, 2026 at 9:35 am

    You got an error because overload resolution has to choose from two equally viable functions (both have user-defined conversions). Function overload resolution is a very complicated subject. For more details on the overload resolution see e.g. this recent lecture by Stephan T. Lavavej. It’s generally best to make single-argument constructors explicit, and then to call your function with an explicit constructor argument.

    test(0L) is not an exact match to any overload because there is no overload test(long). The two overloads you provided both have user-defined conversions on their arguments, but the compiler considers them equally viable. The A overload has to do a standard conversion (long to int) followed by a user-defined conversion (int to A), and the B overload a user-defined conversion (long to B). But both are implicit user-defined conversion sequences.

    How are these ranked? The Standard says in 13.3.3.2 Ranking implicit conversion sequences [over.ics.rank]

    Standard conversion sequence S1 is a better conversion sequence than
    standard conversion sequence S2 if S1 is a proper subsequence of S2

    These type of tie-breaking e.g. apply if A would be a derived class from B (or vice versa). But here neither conversion sequence is a subsequence of the other. Therefore they are equally viable and the compiler cannot resolve the call.

    class A
    {
    public:
        explicit A(int){}
        A(){}
    };
    
    class B: public A
    {
    public:
        explicit B(long){}
        B(){}
    };
    
    void test(A a)
    {}
    
    void test(B b)
    {}
    
    int main()
    {
        test(A(0L));  // call first overload
        test(B(0L)); // call second overload
        return 0;
    }
    

    NOTE: it’s int main(), not void main().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following case: void Set(const std::function<void(int)> &fn); void Set(const std::function<void(int, int)> &fn); Now
Following code worked fine abstract class FunctionRunnable<V> implements Runnable { protected abstract V calculate();
With the 4.2.1 g++ compiler I get the following error: functions.cpp:24: error: call of
I'm trying to understand how to select the right overloaded function template at compile-time
I've been trying to call the overloaded table::scan_index(std::string, ...) member function without success. For
How do I call the correct overloaded function given a reference to an object
I have a class X which has this method: void setRxHandler(void (*h)(int)); And I
In .net framework I constantly see overloaded functions like the following, public void Log(string
While porting Windows code to Linux, I encountered the following error message with GCC
I have implemented the IEquatable interface in a class with the following code. public

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.