...
In this noncompliant code example, a user-defined literal n::x
is operator"" x is declared. However, literal suffix identifiers are required to start with an underscore; literal suffixes without the underscore prefix are reserved for future library implementations:
Code Block | ||||
---|---|---|---|---|
| ||||
#include <cstddef> namespace n { unsigned int operator"" x(const char *, std::size_t); } |
Compliant Solution (User-defined Literal)
In this compliant solution, the user-defined literal is named n::operator"" _x
, which is not a reserved identifier:
Code Block | ||||
---|---|---|---|---|
| ||||
#include <cstddef> namespace n { unsigned int operator"" _x(const char *, std::size_t); } |
Note that the name of the user-defined literal is operator"" _x
and not _x
, which would have otherwise been reserved to the global namespace.
Noncompliant Code Example (File Scope Objects)
...