Consider the simple following:
class Test {
public:
static constexpr int a = 1;
}
This is not considered a definition and hence needs the below definition outside of the class.
constexpr int Test::a;
Why?
Consider the simple following:
class Test {
public:
static constexpr int a = 1;
}
This is not considered a definition and hence needs the below definition outside of the class.
constexpr int Test::a;
Why?
Why a in-class initialization of a static constexpr not a definition?
Because of One Definition Rule (ODR). The rule says that there must be exactly one definition of each non-inline non-member and static member variable. Class definitions, due to their nature, are typically included into multiple translation units. If class definition contained a variable definition, then inclusion into multiple translation units would violate the ODR.
Since C++17, the language has inline variables, so you can define such inline variables within class definitions.