Construction of a void Type?

前端 未结 5 1244
青春惊慌失措
青春惊慌失措 2020-12-14 17:13

I was given a piece of code that uses void() as an argument. The code doesn\'t compile... obviously?

Can we instantiate anything of type void

5条回答
  •  无人及你
    2020-12-14 17:52

    C++ (and I say C++, not C) allows (§6.6.3 comma 2) functions with void return type to return a void expression, that is:

    void foo() { return void(); }
    

    But notice it is not constructing a temporary void!

提交回复
热议问题