Yet another static
question.
I have read the following:
If StaticTest.h
is shared between difference source files then you will get undefined behaviour.
If you define a class or inline functions in different translation units then their definitions must be the same (same sequence of tokens) and, crucially, any identifiers must refer to the same entity (unless a const
object with internal linkage) as in the definition in another translation unit.
You violate this because counter
has internal linkage so in different translation units the identifier in the function definitions refers to a different object.
Reference: C++03 3.2 [basic.def.odr] / 5.