编译此代码时(没有任何标题)
template <typename T>
struct Temperature {
T temp;
explicit Temperature(T t)
: temp(t)
{}
};
Temperature<long double> operator "" _f (long double t)
{
return Temperature<long double>((t - 32) / 1.8);
}
int main()
{
auto t = 100.0_f;
t.temp;
100.0_f.temp; // ERROR AT THIS LINE
return 0;
}
编译器(Ubuntu 14.04上的g ++ 4.8和clang ++ 3.4)都会抱怨
error: unable to find numeric literal operator ‘operator"" _f.temp’
100.0_f.temp;
^
好像是 _f.temp
被认为是那里的后缀。为什么编译器会这样解析它,而不是停留在点?