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

前端 未结 7 655
轻奢々
轻奢々 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

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

    def f():
       pass
    

    becomes

    void f() {}
    

    and

     class C:
         pass
    

    becomes

     class C {};
    

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

     class MyError(Exception):
            pass
    

    becomes

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

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

    Hope that helps.

提交回复
热议问题