I am using same class name in two namespaces, say A and B. Should the include guards be unique while declaring the classes with different namespaces too?
I mean can’t there be two files names AFile.h (in different directories) with same include guards and declaring different namespaces?
//File 1:
#ifndef AFILE_H
#define AFILE_H
namespace A {
class CAFile {...
};
};
#endif
//File 2:
#ifndef AFILE_H
#define AFILE_H
namespace B {
class CAFile {...
};
};
#endif
Your guards need to be different if some code (directly or indirectly) needs to see both A::CAFile and B::CAfile.
The include guards are dealt with by the preprocessor, that has no knowledge at all of classes (let alone namespaces). If both these files are included when processing a c++ file, and they have the same header guards, only one of the declarations will remain in the preprocessed source that the compiler will see.
Look at things like Boost files, they have some conventions for the header guards (if I remember correctly).