static constant floating point need constexpr

Prior to C++11, only static const data members of
integral or enumeration type could have initializers
in the class definition. C++11 extends that to
floating point types (float, double) as well.
However, in order for such members to be initialized
in the class defintion, such members must either be
constexpr or non-static.
This commit is contained in:
Arun Saha
2017-06-03 19:59:20 -07:00
parent 6daacceacc
commit cc81a9b4c5

View File

@@ -16,7 +16,7 @@ namespace my_project {
// if the above macro would be expanded, then the following line would be:
// static const double 3.14159 = 3.14159;
// which leads to a compile-time error. Sometimes such errors are hard to understand.
static const double PI = 3.14159;
static constexpr double PI = 3.14159;
};
}
```