Reputation: 4946
When in-class member initialization is strictly mandatory?
Rules for in-class member initialization are complex and we could avoid that by using Ctor initializer list for non-static members and define static members outside the class. IMHO, this also separates declaration and definition more.
Upvotes: 1
Views: 129
Reputation:
A static constant member must have an initialiser if it's used in-class in a context where a constant expression is required. For example,
struct S {
static const int N = 4;
int arr[N]; // okay
};
const int S::N;
struct T {
static const int N;
int arr[N]; // error
};
const int T::N = 4;
Upvotes: 3