2
 #include <stdint.h>
 class Something { ...
  void put(int32_t value, int32_t scale = 0);
  void put(int64_t value, int32_t scale = 0);
  void put(bool value);
 };

a calls to something.put(4LL) is ambiguous. How is int64_t defined so that it is not a perfect match for long long int constant, which is what the error message tells me it is?

bmargulies
  • 97,814
  • 39
  • 186
  • 310
  • 2
    Maybe `int64_t` is `long`. – user2357112 Jun 17 '15 at 20:05
  • Just taking a guess here, but 4LL is still 4 and 4 will fit in both a 32bit or 64bit integer...could be wrong though – Thomas Jun 17 '15 at 20:06
  • @Thomas: What's relevant for overload resolution is the type, not the value. `4LL`, `4L`, and `4` all have the same mathematical value, but they're all of different types. – Keith Thompson Jun 17 '15 at 20:19
  • @KeithThompson Ok that makes sense, like I said wasn't sure. Haven't done any hard core C++ coding in a while. I need to go and get a c++11 book hah alot has changed – Thomas Jun 17 '15 at 20:20
  • I expected this to be a duplicate, and, indeed, it was; I just couldn't find it for myself. – bmargulies Jun 17 '15 at 20:48

1 Answers1

2

int64_t is a typedef (i.e., an alias) for some predefined type. It could be long long int, or long int, or even int if type int happens to be 64 bits.

Overload resolution is based on the type of the argument, not its value or its size. Even if long long and int64_t have exactly the same size and representation (as they very likely do), they're still distinct types. 4LL is of type long long; that may or may not be the same type as int64_t.

If you want to call put() with an int64_t value of 4, you'll need to ensure that your argument is of the right type. For example:

const int64_t arg = 4;
put(arg);

or

put(int64_t(4));
Keith Thompson
  • 254,901
  • 44
  • 429
  • 631