C
cppcraze
Hi,
I am just stumbled by a problem about concatenation in macro. See
below code snippet:
// there're some contants definition in this class
struct X
{
enum {A, B, C};
};
// and here I want to define a utility macro to help me generate some
functions
#define MK_FUNC(arg) \
int get##arg() \
{ \
return X::##arg; \
}
MK_FUNC(A)
MK_FUNC(B)
MK_FUNC(C)
#undef MKFUNC
// then I can use getA(), getB() .... in my program.
But the preprocessor always complains:
warning: pasting "::" and "A" does not give a valid preprocessing
token
warning: pasting "::" and "B" does not give a valid preprocessing
token
warning: pasting "::" and "C" does not give a valid preprocessing
token
I really don't why this will happen. Isn't this usage in the macro
"X::##arg" an invalid ? Hope someone can help me out.
- Martin
I am just stumbled by a problem about concatenation in macro. See
below code snippet:
// there're some contants definition in this class
struct X
{
enum {A, B, C};
};
// and here I want to define a utility macro to help me generate some
functions
#define MK_FUNC(arg) \
int get##arg() \
{ \
return X::##arg; \
}
MK_FUNC(A)
MK_FUNC(B)
MK_FUNC(C)
#undef MKFUNC
// then I can use getA(), getB() .... in my program.
But the preprocessor always complains:
warning: pasting "::" and "A" does not give a valid preprocessing
token
warning: pasting "::" and "B" does not give a valid preprocessing
token
warning: pasting "::" and "C" does not give a valid preprocessing
token
I really don't why this will happen. Isn't this usage in the macro
"X::##arg" an invalid ? Hope someone can help me out.
- Martin