Undefined reference to a static member of the class

In your *.cpp file add

int ClassName::value = 0;

This will allocate storage for a value.

The piece of code that you actually have in a class declaration just declares this variable (makes the compiler aware that such a variable exists). However, each variable must be declared and defined. A definition will make sure the storage is put aside for this variable and create a symbol your compiler was unable to find before.

Leave a Comment