Clang 3.1 声称支持用户定义的文字。我可以这样定义:
int operator"" _tryit(long double n) { return int(n); }
但是当我尝试使用它时出现错误:
int m = 5_tryit;
Invalid suffix
'_tryit'
on integer constant
最佳答案
5
在您的情况下不能隐式转换为 long double
。您需要将其更改为 5.0
以使其成为 long double 或自己显式调用该函数以使隐式转换起作用:
int m = 5.0_tryit;
或
int n = operator"" _tryit(5);
(均使用 clang 版本 3.1(trunk)(llvm/trunk 155821)
进行了测试
This SO question对规则有很好的解释。
(另外,正如 abarnert 提到的,确保在编译时将 -std=c++11
标志传递给编译器)。
关于c++ - Clang 3.1 和用户定义的文字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10889697/