Sample.h
namespace Testing
{
enum Type
{
DATA = 0,
MORE_DATA
};
}
Now in Sample2.h, using the same namespace, can I access the DataType defined in Sample.h, without including it?
namespace Testing
{
Type test;
}
The question has come up, because I have files that implement this, and seem to build with no problem.
Another user is trying to build, but reports that he has to #include “Sample.h” in Sample2.h in order to build.
Yes, you will need to include Sample.h within Sample2.h. The definition of
Typeis not visible to the compiler within Sample2.h simply because the namespace name is the same within the 2 files.The only thing you gain by having the same namespace names in the 2 files is that
Typedoes not need to have its namespace stated explicitly in Sample2.h. For instance, if the 2 namespaces were not the same:Sample.h
Sample2.h