简体   繁体   中英

User-defined literals, C++ 20.0

In User-defined literals of C++ reference.

published in the Hyperlink https://en.cppreference.com/w/cpp/language/user_literal , What does it mean by:

" 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.


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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM