When having a static variable in a struct/class, within the struct the variable is declared without initialisation and the variable is defined (and initialised) at global level - usually just before main().
If you're using C++17, you can use inline:
1 2 3 4 5 6 7
struct X {
inlinestaticint k = 0;
};
int main() {
X::k = 2;
}
or if you want a const static, then
1 2 3 4 5 6
struct X {
conststaticint k = 99;
};
int main() {
}