Construction of a void Type?

前端 未结 5 1223
青春惊慌失措
青春惊慌失措 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:42

    You can use void() as a callable type, as an example std::function f; is a valid statement.

    Moreover, as from 8.3.5/4:

    A parameter list consisting of a single unnamed parameter of non-dependent type void is equivalent to an empty parameter list.

    That means that this is valid:

    template
    struct F;
    
    template
    struct F { };
    
    int main () {
       F s;
    }
    

    Here you are not instantiating anything of type void, but you are using it (let me say) as a parameter list of a callable type.

    Not sure if this replies to your question, I've not clear what the question actually is.

提交回复
热议问题