C++14: If a constexpr static data member is odr-used, a definition at namespace scope is still required, but it cannot have an initializer.
C++17: If a static data member is declared constexpr, it is implicitly inline and does not need to be redeclared at namespace scope. This redeclaration without an initializer (formerly required) is still permitted, but is deprecated.
#include <iostream>
struct Seasons {
Seasons();
private: staticconstexprconstchar * const season_names[4] = { "Spring", "Summer", "Fall", "Winter" };
};
// C++14: this definition is required, but it cannot have an initializer.
// C++17: this definition is permitted, but it is not required (it is deprecated)
// comment out the following line, and with -std=c++14, there would (or at least should) be an error
// (note: the GNU compiler does swalow this without choking, even in strict C++14 mode.
// AFAIK, it is non-conforming in this regard.)
constexprconstchar * const Seasons::season_names[4]; // this was required before C++17
Seasons::Seasons() {
int INDEX = 0;
// the static data member is odr-used in the following line
std::cout << "ESTACION: " << season_names[INDEX] << '\n' ;
}
int main() {
Seasons s ;
}