What's the meaning of “##” in a C++ macro? [duplicate]

喜你入骨 提交于 2019-12-02 01:49:49

The operator ## concatenates two arguments leaving no blank spaces between them: e.g.

#define glue(a,b) a ## b
glue(c,out) << "test";

This would also be translated into:

cout << "test";

It concatenates tokens without leaving blanks between them. Basically, if you didn't have the ## there

public: inline varType getfunName(void) const { return varName; }\

the precompiler would not replace funName with the parameter value. With ##, get and funName are separate tokens, which means the precompiler can replace funName and then concatenate the results.

This is called token pasting or token concatenation.

The ## (double number sign) operator concatenates two tokens in a macro invocation (text and/or arguments) given in a macro definition.

Take a look here at the official GNU GCC compiler documentation for more information.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!