Skip to content

Commit cc81a9b

Browse files
committed
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.
1 parent 6daacce commit cc81a9b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

05-Considering_Maintainability.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace my_project {
1616
// if the above macro would be expanded, then the following line would be:
1717
// static const double 3.14159 = 3.14159;
1818
// which leads to a compile-time error. Sometimes such errors are hard to understand.
19-
static const double PI = 3.14159;
19+
static constexpr double PI = 3.14159;
2020
};
2121
}
2222
```

0 commit comments

Comments
 (0)