In my C++ .h
file:
class foo {
#define useThis true
...
}
In my .cpp
file:
#if useThis
... generate A code
#else
... generate B code
#endif
The problem is that the #define
values are not being read in the .cpp
file, so what is happening is both A and B are being generated.
I am including the .h
file in the top of the .cpp
file.
Boolean value can not be used in macros for some compilers, like Visual Studio (works under g++ though). A cross compiler way should be:
#define useThis 1
Or, define a macro without value, and use ifdef
to test if it has been defined:
#define useThis
#ifdef useThis
...
#else
...
#endif
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.