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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:07:35+00:00 2026-05-23T22:07:35+00:00

I’m learning c++ and using C++ Primer. Consider the following exercise 14.46: class Complex

  • 0

I’m learning c++ and using C++ Primer. Consider the following exercise 14.46:

 class Complex {
     Complex(double);
     // ...
 };

 class LongDouble {

     friend LongDouble operator+(LongDouble&, int);  // (1)

 public:
     LongDouble(int);

     operator double();

     LongDouble operator+(const Complex &);  // (2)
     // ...
  };

 LongDouble operator+(const LongDouble &, double);  // (3)

 LongDouble ld(16.08);
 double res = ld + 15.05; // which operator+ ?

When I compile using gcc 4.5 the above program, I get

14_46.cpp:60:21: error: ambiguous overload for ‘operator+’ in ‘ld + 1.5050000000000000710542735760100185871124267578125e+1’
14_46.cpp:60:21: note: candidates are: operator+(double, double) <built-in>
14_46.cpp:35:5: note:                 LongDouble LongDouble::operator+(const Complex&)
14_46.cpp:45:1: note:                 LongDouble operator+(const LongDouble&, double)
14_46.cpp:17:5: note:                 LongDouble operator+(LongDouble&, int)

Why is (3) not selected ? Isn’t it exact match?

However, I noticed that removing const-ness of parameter in (3) matches exactly, i.e.,

LongDouble operator+(LongDouble &, double);  // (4)

Using (4) there is no ambiguity. Am I missing something here?

  • 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-23T22:07:36+00:00Added an answer on May 23, 2026 at 10:07 pm

    You have the following competing user defined functions (candidates)

    operator+(LongDouble&, int); // friend
    operator+(LongDouble&, Complex const&); // member
    operator+(LongDouble const&, double); // global
    

    You are invoking this with arguments:

    (LongDouble&, double)
    

    For the first argument, the first two candidates are better than the last. For the second argument, the last candidate is better than the first two candidates. No candidate has at least as good matches as all the others for all arguments, and better matches for some arguments.

    You cannot figure out a clear winner for this situation. This is what I like to call the “criss cross”.

    There are builtin candidates too that are considered among user defined candidates.

    operator+(double, double);
    operator+(int, double);
    ...
    

    From all the builtin candidates, operator+(double, double) would match best. But that would require a user defined conversion for the first argument, which is worse than all the three other user defined operators for the first argument, so it cannot win either.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I am using Paperclip to handle profile photo uploads in my app. They upload
I have text I am displaying in SIlverlight that is coming from a CMS

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.