error: '#' is not followed by a macro parameter

error: '#' is not followed by a macro parameter

我正在尝试编写一个宏,为 C 中任何给定 class 对象的对象池生成代码。 每当我 运行 预处理器

时,我总是得到 error: '#' is not followed by a macro parameter

我试过将 x##y 替换为:

#define CONCAT1(x, y) x##y
#define CONCAT2(x, y) CONCAT1(x, y)

这是在类似问题中提出的建议

#define CONCAT1(x, y) x##y
#define CONCAT2(x, y) CONCAT1(x, y)

#define DECLARE_POOL(CLASS, LEVEL1, LEVEL2) {\
\
    #define CONCAT2(CLASS, _Pool_Level1) LEVEL1\
    #define CONCAT2(CLASS, _Pool_Level2) LEVEL2\
\
    CLASS* CONCAT2(CLASS, _Pool)[LEVEL1] = { 0 };\
\
    int CONCAT2(CLASS, _Available_Head) = -1;\
    int CONCAT2(CLASS, _Available_Tail) = -1;\
\
    int CONCAT2(CLASS, _In_Use_Head) = -1;\
    int CONCAT2(CLASS, _In_Use_Tail) = -1;\
\
    int CONCAT2(CLASS, _Increase_Pool)(int Level1_Address){\
\
    }\
\
    int CLASS(int Address) {\
\
    }\
\
    int CONCAT2(CLASS, _Delete)(int Address) {\
\
    }\
\
    int CONCAT2(CLASS, s)(int Address)\
\
    }\
\
    int CONCAT2(CLASS, _Save_All)(void)\
\
    }\
\
    int CONCAT2(CLASS, _Restore_All)(void)\
\
    }\
    int CONCAT2(CLASS, _Free_All)(void)\
\
    }\
}

预期:代码通过预处理器并为 "CLASS"
类型的对象提供函数原型 实际结果:

error: '#' is not followed by a macro parameter
#define DECLARE_POOL(CLASS, LEVEL1, LEVEL2) {\

您不能在宏中使用 #define。或任何其他预处理器指令,就此而言。