#用空格定义

2022-01-11 00:00:00 macros c++ c-preprocessor

是否可以用空格编写define,例如:

Is it possible to write define with spaces such as:

#define replace to replacement here

我想将replace to"替换为replacement here".

我想测试私有成员:

我确实写过

#define private public

但它不适用于 Qt 中的私有插槽

but it didn't work for private slots in Qt

所以我打算使用类似的东西

so my intend was to use something like

#define private slots: public slots:

无论如何,我找到了另一种测试插槽的方法,顺便说一下,我知道这是一个丑陋的 hack.

anyway I have found another way to test slots and by the way I'm aware of that this is an ugly hack.

推荐答案

不,你不能

#define identifier something

你定义的必须是一个不能包含空格的标识符.也不能包含连字符、以数字开头等,只能定义标识符

what you define must be an identifier which cannot contain space. Nor can it contain hyphen, begin with a number, etc. you can define only an identifier

你写的会起作用

#define replace to replace here

但不是你所期望的.这一行定义了 replace 被替换为 to replacement here

but not as you expect. This line defined replace to be substituted with to replacement here

相关文章