User-defined literals

465 Views Asked by At

In "User-defined literals" on cppreference.com, what does it mean by this?

b) otherwise, the overload set must include either, but not both, a raw literal operator or a numeric literal operator template. If the overload set includes a raw literal operator, the user-defined literal expression is treated as a function call operator "" X("n")

Please, I need a simple example that illustrate this text.

1

There are 1 best solutions below

2
Nimrod On BEST ANSWER

unsigned long long operator "" _w(unsigned long long);
unsigned operator "" _u(const char*);

int main() {
    12_w; // calls operator "" _w(12ULL)
    12_u; // calls operator "" _u("12")
}

A little bit changes based on the example in your link.

Here 12_w calls operator "" _w(12ULL) since there is a literal operator with the parameter type unsigned long long, while 12_u calls operator "" _u("12") since there is only a raw literal operator.