Is there an equivalent of Pythons `pass` in c++ std11?

Is there an equivalent of Pythons `pass` in c++ std11?

A null statement (just Semicolon), or empty brackets should work for you

For example Pythons

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

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;

No. You dont have pass or equivalent keyword. But you can write equivalent code without any such keyword.

def f():


void f() {}


 class C:


 class C {};

In different context, different syntax could be useful. For example,

 class MyError(Exception):


class MyError : public std::exception
      using std::exception::exception; //inherits constructor!

As you can see, in this context, youve to write using to inherits constructors from the base class. In Python, pass does the similar thing, in similar context.

Hope that helps.

Is there an equivalent of Pythons `pass` in c++ std11?

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 doesnt actually support it either, after all.

Write an if statement, instead:

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

Leave a Reply

Your email address will not be published.