I think you mean "field" instead of "attribute"
Your code is valid C++ but it does not initialize the static field global
, as it's an instance constructor.
If you want to initialize NixIs::global
with a trivial constant value (known at compile-time) you can specify it inline in the header:
NixIs.h:
class NixIs {
static int global = 0;
}
If you have a non-constant initial value (such as a parameterless free-function result) then the static field initializer needs to be in a code-file (instead of a header). You need to specify the static field in addition to its type and the initial value of the static field:
NixIs.h:
class NixIs {
static int global;
}
NixIs.cpp:
int NixIs::global = nonTrivialValue;
If you want to initialize multiple static fields in a particular order or with function-result values you'll need to use a hack because C++ does not have static constructors. See here: Static constructor in c++