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++ 中## 运算符的用途是什么,它叫什么?
基础教程推荐
- 提升 ASIO 流缓冲 2021-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- c++ STL设置差异 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
