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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:14:03+00:00 2026-06-12T17:14:03+00:00

why do we not see a undefined call to overloaded function error with the

  • 0

why do we not see a “undefined call to overloaded function” error with the code bellow? just because int is a built in type? where in the standard can I find the guarantee for the conversion to built in type, such as in the code bellow?… thanks!

#include <iostream>
using namespace std;

class B {
public:
operator int(){ return 0; }
};

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

void f ( int i ) { cout << "overload f(int) was used!";};
void f ( A a )   { cout << "overload f(A) was used!" ;};


int main () {
  B b;
  f( b );
}
  • 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-12T17:14:04+00:00Added an answer on June 12, 2026 at 5:14 pm

    It has nothing to do with being a built-in type. You defined operator int for B. This means that you have provided a user-defined conversion from B to int. According to 12.3.4 of the standard, “at most one user-defined conversion (constructor or conversion function) is implicitly applied to a single value.” This is why it is not converted to A, because that would require two implicit conversions.

    The rules for determining exactly when this happens are somewhat complicated, so many people advise that you avoid providing user-defined conversions. Another way of defining these is to provide a constructor with one argument; you can add explicit to the beginning to avoid it being applied implicitly.

    When you call f(b), the compiler applies the conversion that you provided to convert b to int. If you want to convert it to A, you’ll have to define a conversion from B to A, or apply one of the conversions explicitly, like f(int(b)) or f(A(b)).

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

Sidebar

Related Questions

I do not see how this recursive function works: function f(n) { g(n-1) }
Why do I not see the spinner image when I run this code? However
So because Javolution does not work ( see here ) I am in deep
I do not understand the error in compilation. I don't see any syntax problems.
Notice (8): Undefined variable: form [[...], line 64] Fatal error: Call to a member
I am getting the following error: Fatal error: Call to undefined method MDB2_Error::quoteIdentifier() The
Please see the code here: http://pastie.org/1092106 When I call the method createPost on Blog,
as you see in the code below. I have a jQuery function called externally.
Stumped by this one. This code is giving me PHP Fatal error: Call to
Why one project (exe) does not see the namespace of another project (dll) in

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.