C++ 中## 运算符的用途是什么,它叫什么? [英] What is the purpose of the ## operator in C++, and what is it called?

查看:25
本文介绍了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++ 中## 运算符的用途是什么,它叫什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆