Why does this code:
constexpr float operator "" _deg(long double d) {
// returns radians
return d*3.1415926535/180;
}
static const float ANGLES[] = {-20_deg, -10_deg, 0_deg, 10_deg, 20_deg};
Produce 5 of these errors:
error: unable to find numeric literal operator ‘operator”” _deg’
I am using GCC 4.7.3. (arm-none-eabi-g++, with the -std=c++0x flag).
It seems GCC doesn’t do type conversions with user-defined literals, so e.g. the
-10in-10_degis considered to be an integer.Add
.0to all numbers and it should hopefully work:Of course, you can also add another operator function taking
intas argument.