Clang 3.1 声称支持用户定义的文字。我可以这样定义:
int operator"" _tryit(long double n) { return int(n); }
但是当我尝试使用它时出现错误:
int m = 5_tryit;
'_tryit'
整数常量的后缀无效
5
在您的情况下,不能隐式转换为 a long double
。您需要对其进行更改5.0
以使其成为 long double 或自己显式调用该函数以使隐式转换起作用:
int m = 5.0_tryit;
或者
int n = operator"" _tryit(5);
(用 测试过clang version 3.1 (trunk) (llvm/trunk 155821)
)
这个 SO question对规则有很好的解释。
(另外,正如 abarnert 提到的,确保-std=c++11
在编译时将标志传递给编译器)。