I have the following 2 macros:
#define SCOPED_ENUM_HEADER(NAME) struct NAME{ enum _NAME{
#define SCOPED_ENUM_FOOTER(NAME) };}; typedef NAME::_NAME NAMEtype;
Only the first instance of NAME get replaced by the passed NAME. What’s wrong with it?
Is is to be used in such a way:
SCOPED_ENUM_HEADER(LOGLEVEL)
UNSET,
FILE,
SCREEN
SCOPED_ENUM_FOOTER(LOGLEVEL)
The problem is that
NAMEis not the same as_NAME; they are two totally separate identifiers.If you want to add an underscore to the front of whatever the parameter
NAMEis, use the concatenation (##) operator:You do need to be really careful with prepending an underscore, though. All identifiers beginning with an underscore followed by a capital letter are reserved to the implementation.