我有一个预处理器宏,它根据宏参数生成函数和变量。
用 A 依次调用宏,B 宏会生成类似
Inst* AActivate() { ... }
bool Atemp;
Inst* BActivate() { ... }
bool Btemp;
由于宏是在头文件中定义的,因此我收到链接器错误,通知我有关已定义的符号。我曾经使用过#pragma,但我想问题在于在标头中实现函数。
这是宏:
#define REGISTER(ns, id, type) \
Inst* type##Activate() { return new type(); }\
bool type##temp = RegisterType(ns << 8 | id, &type##Activate);
现在我想知道如何处理这些问题。我的第一个想法是使用一些#define-Guards,但显然这需要嵌套的#defines,这在 C++ 中是不可能的。我阅读了有关 boost 的可能解决方案,但不幸的是,我无法使用这些库。
任何的想法?
先感谢您...