If I have a #define statement within a namespace as such:
namespace MyNamespace
{
#define SOME_VALUE 0xDEADBABE
}
Am I correct in saying that
Correct,#define
's aren't bound by namespaces. #define
is a preprocessor directive - it results in manipulation of the source file prior to being compiled via the compiler. Namespaces are used during the compilation step and the compiler has no insight into the #define
's.
You should try to avoid the preprocessor as much as possible. For constant values like this, prefer const over #define
's.