Is there an equivalent of Python's `pass` in c++ std11?

前端 未结 7 549
轻奢々
轻奢々 2021-01-01 10:26

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

Edit: Just saw: How do

7条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-01 10:28

    As has been stated in the comments, this is not supported because it makes no sense. The conditional operator is designed to evaluate to one of two operands. Two. Not one.

    It is not okay to abuse the operator to perform some conditional action in only one of those cases. In fact, it is best that neither operand have any side-effects whatsoever. This is not a "do something" construct, but a "give me one of two things" construct.

    In this regard, if Python were to support what you say it supports, then it would be broken where C++ is not. As it happens, Python doesn't actually support it either, after all.

    Write an if statement, instead:

    if (x > y) {
       do_something();
    }
    else {
       /* Unimplemented at the moment */
    }
    

提交回复
热议问题