The code:
#include <stdint.h>
struct HashType64
{
inline HashType64(uint64_t h) noexcept : _h(h) {}
inline operator uint64_t() const noexcept { return _h; }
inline operator int64_t() const = delete;
inline operator int32_t() const = delete;
inline operator uint32_t() const = delete;
private:
uint64_t _h;
};
uint64_t f() {
return HashType64(0) & 0xFFULL;
}
The error:
<source>: In function 'uint64_t f()':
<source>:17:26: error: ambiguous overload for 'operator&' (operand types are 'HashType64' and 'long long unsigned int')
17 | return HashType64(0) & 0xFFULL;
| ~~~~~~~~~~~~~ ^ ~~~~~~~
| | |
| HashType64 long long unsigned int
<source>:17:26: note: candidate: 'operator&(uint32_t {aka unsigned int}, long long unsigned int)' (built-in)
17 | return HashType64(0) & 0xFFULL;
| ~~~~~~~~~~~~~~^~~~~~~~~
<source>:17:26: note: candidate: 'operator&(int32_t {aka int}, long long unsigned int)' (built-in)
<source>:17:26: note: candidate: 'operator&(int64_t {aka long int}, long long unsigned int)' (built-in)
<source>:17:26: note: candidate: 'operator&(uint64_t {aka long unsigned int}, long long unsigned int)' (built-in)
I understand what the error is about, but I do not understand why it occurs. HashType64
is only convertible to uint64_t
and not to any other integer types, the other overloads are not applicable, how can it be ambiguous?