在c ++ std11中是否有等效于Python的`pass`? [英] Is there an equivalent of Python's `pass` in c++ std11?

查看:46
本文介绍了在c ++ std11中是否有等效于Python的`pass`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个不执行任何操作的语句,但可以在需要该语句的地方使用该语句.通过: http://docs.python.org/release/2.5.2/ref/pass.html

I want a statement that does nothing but can be used in places requiring a statement. Pass: http://docs.python.org/release/2.5.2/ref/pass.html

刚才看到的是:如何执行在C/C ++中没有操作?

#define pass (void)0

解决了我的问题.谢谢!

Solved my problem. Thanks!

推荐答案

分号,否则空括号应该适合您

Semicolon, or empty brackets should work for you

例如Python的

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

可以转换为以下C ++

Could translate to the following C++

while (/* some condition */)
    ;

while (/* some condition */) {}

对于三元运算符,您可以执行以下操作:

Perhaps for the ternary operator case, you could do:

x > y ? do_something() : true;

这篇关于在c ++ std11中是否有等效于Python的`pass`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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