why is it when i already used a protective macro?
Header protectors prevent the contents of the header file from being included more than once in the same block not through a few translation units.
why A::a does not have an error message (I cannot write the code const static obj b={1,2} in class A )
Initialization inside the class is allowed by the compiler as a special case for static data elements of type const literal. Your example is initialization inside a class.
const A::b defines the same symbol name in each translation unit, where the header is included and, therefore, breaks one definition rule .
You need to move the definition to one and only one source cpp file so that it is defined only once.
Alok save
source share