#pragma message("MAP_ENGINE=" BOOST_PP_STRINGIZE(MAP_ENGINE))
#if MAP_ENGINE == CE4
    Type4 x = new Type4();
#elif MAP_ENGINE == CE5
    Type5 x = new Type5();
#endif

This code is supposed to create a var x of different type depending on a preprocessor value. I set MAP_ENGINE in the Visual C++ project settings:

enter image description here

But the CE4 code is still compiled and I get an error. I added the #pragma to check the value is set:

1>MAP_ENGINE=CE5
1>.\MyFile.cpp(141) : error C2039: 'Type4 ' : undeclared identifier

It must be something dumb but I can't see it! Is defining it in the project settings meaning CE4/CE5 isn't actually a defined value perhaps?

有帮助吗?

解决方案

The preprocessor == operator only performs integer arithmetic (macros that don't expand to something that looks like an integer are considered to have a value of 0). It can't be used to compare strings.

Make it something like this:

#if defined(MAP_ENGINE_CE4)
// ...
#elif defined(MAP_ENGINE_CE5)
// ...
#else
  #error Exactly one of MAP_ENGINE_CE4 and MAP_ENGINE_CE5 must be defined
#endif
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top