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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:56:00+00:00 2026-05-15T01:56:00+00:00

Why does VisualC++ (2008) get confused ‘C2666: 2 overloads have similar conversions’ when I

  • 0

Why does VisualC++ (2008) get confused ‘C2666: 2 overloads have similar conversions’ when I specify an enum as the second parameter, but not when I define a bool type?

Shouldn’t type matching already rule out the second constructor because it is of a ‘basic_string’ type?

#include <string>
using namespace std;

enum EMyEnum { mbOne, mbTwo };
class test {
public: 
#if 1 // 0 = COMPILE_OK, 1 = COMPILE_FAIL
    test(basic_string<char> myString, EMyEnum myBool2) { }
    test(bool myBool, bool myBool2) { }
#else
    test(basic_string<char> myString, bool myBool2) { }
    test(bool myBool, bool myBool2) { }
#endif
};

void testme() {
    test("test", mbOne);
}

I can work around this by specifying a reference ‘ie. basic_string &myString’ but not if it is ‘const basic_string &myString’.

Also calling explicitly via “test((basic_string)”test”, mbOne);” also works.

I suspect this has something to do with every expression/type being resolved to a bool via an inherent ‘!=0’.

Curious for comments all the same 🙂

  • 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-15T01:56:00+00:00Added an answer on May 15, 2026 at 1:56 am

    The reason for the ambiguity is that one candidate function is better than another candidate function only if none of its parameters are a worse match than the parameters of the other.

    The problem is that the string literal, which has a type of const char[5] is convertible to both std::string (via a converting constructor) and to a bool (since an array can decay to a pointer, and any pointer is implicitly convertible to bool). The conversion to bool is preferred because it is a standard conversion and standard conversions are preferred to user-defined conversions.

    So, consider the “broken” overloads:

    test(basic_string<char> myString, EMyEnum myBool2) { }  // (1)
    test(bool myBool, bool myBool2) { }                     // (2)
    

    The first argument is a const char[5] and prefers (2) (per the description above). The second argument is an EMyEnum and prefers (1), which is an exact match; a conversion would be required to match (2) (an enumeration can be implicitly converted to a bool).

    Now consider the second case:

    test(basic_string<char> myString, bool myBool2) { }    // (3)
    test(bool myBool, bool myBool2) { }                    // (4)
    

    The first argument still prefers (4), but now the second argument can match both (3) and (4) equally. So, the compiler can select (4) and there is no ambiguity.

    There would be no ambiguity if you eliminated the required conversion for the first argument, e.g.,

    test(basic_string<char>("test"), mbOne);
    

    because both arguments would match (1) exactly.

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

Sidebar

Related Questions

Let say I have the following desire, to simplify the IConvertible's to allow me
I am trying to understand the practical difference during the execution of a program
I want the messagebox to only show if the number is equal to 0.
I'm trying to write test harness for part of my Android mapping application. I
I am attempting to pull some information from my tnsnames file using regex. I
After having read Ian Boyd 's constructor series questions ( 1 , 2 ,

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.