What is the purpose of the ## operator in C++, and what is it called?(C++ 中## 运算符的用途是什么,它叫什么?)
问题描述
我正在查看 DirectX 2009 年 3 月 SDK 附带的 DXUTCore 项目,并注意到他们使用宏来创建通用访问器,而不是创建普通的访问器方法,类似于以下内容:
I was looking through the DXUTCore project that comes with the DirectX March 2009 SDK, and noticed that instead of making normal accessor methods, they used macros to create the generic accessors, similar to the following:
#define GET_ACCESSOR( x, y ) inline x Get##y() { DXUTLock l; return m_state.m_##y;};
...
GET_ACCESSOR( WCHAR*, WindowTitle );
## 运算符似乎只是将第二个参数中的文本插入宏中,以创建一个使用该文本对变量进行操作的函数.这是 C++ 中的标准(即不是 Microsoft 特定的)吗?它的使用被认为是好的做法吗?而且,那个运算符叫什么?
It seems that the ## operator just inserts the text from the second argument into the macro to create a function operating on a variable using that text. Is this something that is standard in C++ (i.e. not Microsoft specific)? Is its use considered good practice? And, what is that operator called?
推荐答案
Token-粘贴操作符,由预处理器用来将两个标记连接成一个标记.
Token-pasting operator, used by the pre-processor to join two tokens into a single token.
这篇关于C++ 中## 运算符的用途是什么,它叫什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++ 中## 运算符的用途是什么,它叫什么?


基础教程推荐
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 我有静态或动态 boost 库吗? 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01