#用空格定义
是否可以用空格编写定义,例如:
#define replace to replacement here
我想将“替换为”替换为“替换此处”。
编辑:
我想测试私有成员:
我确实写过
#define private public
,但它不适用于 Qt 中的私有插槽,
所以我的目的是使用类似的东西
#define private slots: public slots:
,无论如何我已经找到了另一种测试插槽的方法,顺便说一句我知道这一点这是一个丑陋的黑客行为。
Is it possible to write define with spaces such as:
#define replace to replacement here
I want to replace "replace to" with "replacement here".
EDIT:
I want to test private members:
I did write
#define private public
but it didn't work for private slots in Qt
so my intend was to use something like
#define private slots: public slots:
anyway I have found another way to test slots and by the way I'm aware of that this is an ugly hack.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不,您不能
#defineidentifier东西
您定义的必须是一个不能包含空格的标识符。它也不能包含连字符、以数字开头等。您可以仅定义一个标识符,
您编写的内容将起作用
#define Replace to replacement here
但不是您期望的那样。此行定义了要替换为
replace
的to replacement here
no, you can't
#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
what you wrote will work
#define replace to replacement here
but not as you expect. This line defined
replace
to be substituted withto replacement here
您可以...
注意定义的意外副作用。在它们完成工作后,您可能希望
#undef
它们。You could do...
Watch out for unintended side effects of the defines. You would probably want to
#undef
them after they've done their job.如果您正在进行单元测试,您可以使用以下标志编译您的文件
然后在单元测试中,您将能够调用类的每个私有方法。
编辑:
我最近说过,在 gcc 编译器上使用 -fno-access-control 标志允许您访问私有方法或成员。有关该主题的更多信息可以在此处找到:使用 -fno-access-control 进行单元测试< /a>
If you are doing unit test, you can compile your file with the following flag
Then in your unit test, you will be able to call every private method of your class.
EDIT:
I've recently remarked that using the -fno-access-control flag on gcc compiler allows you to access private method or member. More info on that topic can be found here: Unit testing with -fno-access-control
不,那不可能。为什么不直接这样做:
No, that's not possible. Why not just do this instead:
可能不会。
它将理解定义后的第一个单词是标识符名称,其余的是其“主体”。
probably not.
It will understand that the first word after the define is the identifier name and the rest is the "body" of that.