Enabling the TEST security name is likely to conflict with some other macro; use something more complex, such as HEADERNAME_H .
Note: names beginning with an underscore followed by uppercase letters and names containing two consecutive underscores are reserved for implementation.
Secondly, if you are going to put this in the header file, then the function definition must be inline . Otherwise, when you include multiple translation units, you will receive a linker error with multiple definitions. Or more formally, the standard ODR (one definition rule) prohibits such multiple definitions, unless they are inline and are virtually identical.
Edit : delete above because I have not seen the use of an anonymous namespace.
Instead of an anonymous namespace that gives you a separate namespace in each translation unit and a separate (identical) function definition in each such namespace, instead, just use inline - as explained in the crossed out text above.
Cheers and hth.,
source share