1

Why is this an error : ie. arent long long and long double different types ?

../src/qry.cpp", line 5360: 
Error: Overloading ambiguity between "Row::updatePair(int, long long)" 
and "Row::updatePair(int, long double)".

Calling code: . . pRow -> updatePair(924, 0.0); pRow -> updatePair(925, 0.0); .

3
  • 2
    Let us see more of your code especially the code that is calling updatePair Commented Sep 30, 2009 at 15:30
  • btw, it it legitimate to call this a "compiler error"? Maybe it should sound as a "compile error"? Commented Sep 30, 2009 at 15:38
  • does updatePair have a default value for the second argument? Commented Sep 30, 2009 at 15:39

2 Answers 2

3

A constant 0.0 is of type double, which doesn't directly match your overloaded functions. You may expect your compiler to pick the long double version, but the compiler doesn't want to make that assumption for you.

You need to be more explicit about which version you want the compiler to call:

pRow -> updatePair(924, 0.0L);

will call the long double version.

or:

pRow -> updatePair(924, 0LL);

will call the long long version.

Sign up to request clarification or add additional context in comments.

Comments

1
                 $1      $2
Row::updatePair(int, long long) // #1
Row::updatePair(int, long double) // #2


// updatePair(924, 0.0); 
//   int -> int (#1)  // $1#1
//   int -> int (#2)  // $1#2
//
//   double -> long long // $2#1
//   double -> long double // $2#2

In this case, both conversions in the first group are exact matches, while both conversions in the second group are conversions. They are equally ranked - it's like int -> long vs int -> double. The other call has the same types, just different values, so it exhibits the same behavior.

Only float -> double is a promotion, like only integer types smaller than int to int (and for some exotic platforms to unsigned int) are promotions. So the following wouldn't be ambiguous

                 $1      $2
Row::updatePair(int, double) // #1
Row::updatePair(int, long double) // #2


// updatePair(924, 0.0f); 
//   int -> int (#1)  // $1#1
//   int -> int (#2)  // $1#2
//
//   float -> double // $2#1 (promotion - not a ranked as conversion).
//   float -> long double // $2#2

In that case, the second argument has a better conversion sequence when converted to the parameter of #1.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.