"static const int" causes linking error (undefined-reference)

Also see this post: essentially, the problem is that somehow compiler ends up expanding your code into taking the address of Elem::value.


If you want to initialize it inside the struct, you can do it too:

struct Elem {
    static const int value = 0;
};

const int Elem::value;

static class members are generally supposed to be defined outside the class (declared inside, defined outside) in one compilation unit.

I don't remember how that interacts with inline initialization of const static integral members.


Try writing it as

struct Elem {
    static const int value;
};

const int Elem::value = 0;

etc

.