Can someone explain why the following snippet is erronous?
1 2 3 4 5 6 7 8 9 10 11
namespace foo {
constauto a = 2.0;
}
class Test {
public:
Test() {}
conststaticint bar = foo::a;
};
I'm receiving the following error for line 9:
error C2057: expected constant expression
The error is referring to foo::a. If I remove the .0 from foo::a's initialization (as in, it's an int, not a double), the snippet compiles fine.
Does this possibly somehow have to do with non-integral types being disallowed from having in-class initializers? However, Test::bar is an integral type...
Note: Since this International Standard imposes no restrictions on the accuracy of floating-point operations, it is unspecified whether the evaluation of a floating-point expression during translation yields the same result as the evaluation of the same expression (or the same operations on the same values) during program execution.