这行是什么意思?特别是,##
是什么意思?
#define ANALYZE(variable, flag) ((Something.##variable) & (flag))
编辑:
还是有点懵。如果没有 ##
会是什么结果?
最佳答案
A little bit confused still. What will the result be without ##?
通常您不会注意到任何差异。但是, 是有区别的。假设 Something
的类型是:
struct X { int x; };
X Something;
然后看看:
int X::*p = &X::x;
ANALYZE(x, flag)
ANALYZE(*p, flag)
没有标记连接运算符##
,它扩展为:
#define ANALYZE(variable, flag) ((Something.variable) & (flag))
((Something. x) & (flag))
((Something. *p) & (flag)) // . and * are not concatenated to one token. syntax error!
通过标记串联,它扩展为:
#define ANALYZE(variable, flag) ((Something.##variable) & (flag))
((Something.x) & (flag))
((Something.*p) & (flag)) // .* is a newly generated token, now it works!
重要的是要记住预处理器对预处理器标记进行操作,而不是对文本进行操作。所以如果你想连接两个标记,你必须明确地说出来。
关于c++ - #define 中的## 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35500792/