From cc81a9b4c5b3893164f22ada1616ea955c03edbd Mon Sep 17 00:00:00 2001 From: Arun Saha Date: Sat, 3 Jun 2017 19:59:20 -0700 Subject: [PATCH] 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. --- 05-Considering_Maintainability.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/05-Considering_Maintainability.md b/05-Considering_Maintainability.md index 3116412..402a08a 100644 --- a/05-Considering_Maintainability.md +++ b/05-Considering_Maintainability.md @@ -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; }; } ```