Is nullptr_t a default constructible type?

前端 未结 2 1748
孤城傲影
孤城傲影 2021-02-13 01:53

I can\'t tell from the C++11 Standard if nullptr_t has a default constructor. In other words, is the following valid?:

nullptr_t n; 

GCC and VC

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-13 02:38

    While nullptr is a new addition to the language itself, std::nullptr_t is just an alias of an unnamed type, the alias declared in cstddef like this:

    typedef decltype(nullptr) nullptr_t;
    

    While nullptr_t, being a typedef and not a language keyword, is not listed as a fundamental type, it is specified to behave as a fundamental type (and not, for example, as a pointer type or a class type). Therefore it does not have a default constructor, but you can still declare a variable like you have done. Your variable is not initialized and I wonder what its use could be and what error message you exactly got from clang.

    See also here.

提交回复
热议问题