I have a small problem with a define. I want to assign it to an integer variable but the compiler says it’s undeclared.
Here’s what the code looks like: defines.h
#ifndef DEFINES_H #define DEFINES_H #define MYDEFINE 2 #endif
myclass.h
namespace mynamespace { class myClass { int someFunction(); }; }
myclass.cxx
#include 'defines.h' #include 'myclass.h' namespace mynamespace { int myClass::someFunction() { int var = MYDEFINE; return 0; } }
In the line with the int assignment the compiler error takes place. I also tried to use another define, defined in the same header file as above, as a function parameter with the same effect. Any ideas? Thanks in advance.
I know using defines is a bad habit, but I only extend an existing project and I try to stay in their design ways.
EDIT: The error message simply is: Fehler 1 error C2065: 'MYDEFINE': nichtdeklarierter Bezeichner ... As you might see this is not the real source code, but I think I was very careful while putting together the question.
EDIT2: Thanks for the hint with the #warning. There were 2 files with the same name in different folders. I’ve no idea why the compiler didn’t bring this up. Anyway, it works now.
You should check whether the symbol MYDEFINE is really defined.
Check whether the header file where it is declared is really included (and compiled). Use #warning near the define to make sure it is compiled for myclass.cxx:
If it is not compiling (you’ll not find the warning message in compilation log), make a search for DEFINES_H. It might be already defined somewhere else.