views:

218

answers:

2

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  A: 

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.

Commodore Jaeger
+1  A: 
                 $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.

Johannes Schaub - litb