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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:53:32+00:00 2026-05-11T10:53:32+00:00

Can you tell me why the following code is giving me the following error

  • 0

Can you tell me why the following code is giving me the following error – call of overloaded ‘C(int)’ is ambiguous

I would think that since C(char x) is private, only the C(float) ctor is visible from outside and that should be called by converting int to float.

But that’s not the case.

class C {     C(char  x)     {     } public:     C(float t)     {     } };  int main() {     C p(0); } 
  • 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. 2026-05-11T10:53:32+00:00Added an answer on May 11, 2026 at 10:53 am

    This is discussed in ‘Effective C++’ by Scott Meyer. The reason this is ambiguous is that they wanted to ensure that merely changing the visibility of a member wouldn’t change the meaning of already-existing code elsewhere.

    Otherwise, suppose your C class was in a header somewhere. If you had a private C(int) member, the code you present would call C(float). If, for some reason, the C(int) member was made public, the old code would suddenly call that member, even though neither the old code, nor the function it called had changed.

    EDIT: More reasons:

    Even worse, suppose you had the following 2 functions:

    C A::foo()  {     return C(1.0); }  C B::bar()  {     return C(1.0); } 

    These two functions could call different functions depending on whether either foo or bar was declared as a friend of C, or whether A or B inherits from it. Having identical code call different functions is scary.

    (That’s probably not as well put as Scott Meyer’s discussion, but that’s the idea.)

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

Sidebar

Related Questions

The following code is giving me a compilation error. Can anyone please tell me
Can anyone tell me why the following code produces the alert box that I
Can anyone tell me why the following code is causing an error on the
Can anyone tell me why the following code fails to submit the form into
can anybody tell me why is the following code not working? <script type=text/javascript src=../../Scripts/jquery.js></script>
I can't tell if this is a bug or what. The following code works
Can anybody tell me why the following line of code wouldn't be a legitimate
Can someone please tell me how I can implement the following line of pseudo-code.
As far as I can tell, both of the following code snippets will serve
As I'm sure you can tell by the following code, I'm a newbie. But

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.