1
votes

I am trying to create a user defined literal but get an error message when using it. GCC says

unable to find numeric literal operator ‘operator""_uint’

while clang tells me

error: no matching literal operator for call to 'operator""_uint' with argument of type 'unsigned long long' or 'const char *', and no matching literal operator template

I reduced the code to following MCVE:

#include <cinttypes>

unsigned int operator"" _uint(char const *, std::size_t) { return 0; }

int main() {
    return 1_uint;
}

Which gives the mentioned error as you can see on ideone.

1

1 Answers

0
votes

As you can read in detail on cppreference.com there is a multitude of different versions for literal operators.

The one in the OP is used exclusively for string literals and won't be available for integers. Instead the "fallback" version for integers which expects only a const char* without a second std::size_t parameter:

#include <cinttypes>

unsigned int operator"" _uint(char const *) { return 0; }

int main() {
    return 1_uint;
}

Which works on ideone.