Why can't you take the address of nullptr?

后端 未结 4 1147
野性不改
野性不改 2021-02-05 00:39

In the C++11 standard, I don\'t understand the reason why taking the address of nullptr is disallowed whereas one is allowed to take the address of their own st

4条回答
  •  遥遥无期
    2021-02-05 01:03

    It's the same as not being able to take the address of 5 even though you can take the address of an int after giving it the value 5. It doesn't matter that there's no alternative value for a nullptr_t to have.

    Values don't have addresses; objects do.

    A temporary object is generated when you pass such a value to a const & parameter, or otherwise bind a value to a const reference, such as by static_cast< T const & >( … ) or declaring a named reference T const & foo = …;. The address you're seeing is that of the temporary.

提交回复
热议问题