Clang 3.1 and user literals

Clang 3.1 claims to support user-defined literals. I can define this:

int operator"" _tryit(long double n) { return int(n); }

but when I try to use it, I get an error:

int m = 5_tryit;

Invalid suffix '_tryit'for integer constant

+5
source share
1 answer

5cannot be implicitly converted to long doublein your case. You need to change it to 5.0to make it long double or to explicitly call the function yourself to implicitly convert to work:

int m = 5.0_tryit;

OR

int n = operator"" _tryit(5);

(verified as with clang version 3.1 (trunk) (llvm/trunk 155821))

This SO question has a good explanation of the rules.

( , abarnert, , -std=c++11 ).

+7

All Articles