C++宏中"##"的含义是什么?

Bes*_*ter 2 c c++ c-preprocessor

以下"##"的含义是什么?

#define CC_SYNTHESIZE(varType, varName, funName)\
protected: varType varName;\
public: inline varType get##funName(void) const { return varName; }\
public: inline void set##funName(varType var){ varName = var; }
Run Code Online (Sandbox Code Playgroud)

Ed *_*eal 6

运算符##连接两个参数,它们之间没有空格:例如

#define glue(a,b) a ## b
glue(c,out) << "test";
Run Code Online (Sandbox Code Playgroud)

这也将被翻译成:

cout << "test";
Run Code Online (Sandbox Code Playgroud)