gpt4 book ai didi

c++ - c++ std11中是否有相当于Python的 `pass`?

转载 作者:IT老高 更新时间:2023-10-28 20:51:03 34 4
gpt4 key购买 nike

我想要一个什么都不做但可以在需要声明的地方使用的声明。通行证:http://docs.python.org/release/2.5.2/ref/pass.html

编辑:刚刚看到:How does one execute a no-op in C/C++?

#define pass (void)0

解决了我的问题。谢谢!

最佳答案

空语句(只是分号)或空括号应该适合您

例如 Python 的

while some_condition():    # presumably one that eventually turns false
pass

可以翻译成下面的C++

while (/* some condition */)
;

或者

while (/* some condition */) {}

也许对于三元运算符的情况,你可以这样做:

x > y ? do_something() : true;

关于c++ - c++ std11中是否有相当于Python的 `pass`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20382278/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com