Good question! The answer is that the library has no choice but to guarantee that the definition of a static member is performed only once. If a static member is defined multiple times, the behavior is undefined. As with anything falling under the One Definition Rule, the easiest fix is to provide a header with your declarations for inclusion in however many files you want:
#ifndef C_H
#define C_H
class C {
...
static int data;
...
};
#endif And then a source file that is linked with the project once and provides definitions for declared names in the header file:
#include "c.h"
int C::data = 0;
This is a safe and easy way to avoid multiple definitions, especially for situations where an error or warning is not required, such as this one.
