我通读了一些示例代码,并了解了这个我以前从未见过的 ## 语法。代码示例如下:
#define DEF_MAKE_BT_1_COMP(BT)\
inline i_##BT make_i_##BT(i_##BT::vtype x) { return make_##BT(x); }
#define DEF_MAKE_BT2(T) \
DEF_MAKE_BT_1_COMP(T##1); \
DEF_MAKE_BT_2_COMP(T##2);
DEF_MAKE_BT2(double);
当我在最后一行出错时,“make_double1”未定义。有人以前见过这种语法吗?
##
是连接两个标记的预处理器运算符。
来自 http://en.cppreference.com/w/cpp/preprocessor/replace
A ## operator between any two successive identifiers in the replacement-list runs parameter replacement on the two identifiers (which are not macro-expanded first) and then concatenates the result. This operation is called "concatenation" or "token pasting". Only tokens that form a valid token together may be pasted: identifiers that form a longer identifier, digits that form a number, or operators + and = that form a +=. A comment cannot be created by pasting / and * because comments are removed from text before macro substitution is considered. If the result of concatenation is not a valid token, the behavior is undefined.