So, I'm aware that in C++ static members can be initialized inside the class if they are a const literal type like the following
class test{
static constexpr int stc = 1;
private:
int a = 0;
int b = 0;
int c = 0;
};
and the static constexpr variable stc
can be used where the compiler can directly substitute the value of the member i.e
int array[stc];
However, if used in a context where the value cannot be directly substituted by the compiler then the compiler generates an error unless the static member is defined outside the class like so:
constexpr int test::stc;
Why is this the case?
Aucun commentaire:
Enregistrer un commentaire