I'm having an awkward problem in Visual Studio 2008. I'm trying to define a string-to-enum mapping using a config header (call it param_defines.h) file which looks something like this:
DEFINE_ITEM( A, BOOLEAN )
DEFINE_ITEM( B, INT )
DEFINE_ITEM( C, INT )
And so on. This is then referenced in a second header (enums.h) file:
enum ParamType
{
BOOLEAN = 0,
INT
};
enum Param
{
UNKNOWN = -1
#define DEFINE_ITEM( NAME, TYPE ) ,NAME
#include "param_defines.h"
#undef DEFINE_ITEM
};
Then in a third (source) file I'm doing this:
#include "enums.h"
std::tr1::unordered_map<std::string, int> params;
#define DEFINE_ITEM( NAME, TYPE ) params[ #NAME ] = NAME
#include "param_defines.h"
#undef DEFINE_ITEM
When I compile the source file I a load of errors like:
error C2065: 'A': undeclared identifier
error C2065: 'B': undeclared identifier
error C2065: 'C': undeclared identifier
So something is going on with the preprocessor isn't quite doing what I want it to do.
The kicker is this. I set /P so I have some way of diagnosing what's going wrong. When I do this, the file compiles successfully.
Aucun commentaire:
Enregistrer un commentaire