Why don't iostream objects overload operator bool?

前端 未结 3 1587
無奈伤痛
無奈伤痛 2020-12-06 18:15

In this answer I talk about using a std::ifstream object\'s conversion to bool to test whether the stream is still in a good state. I looked in th

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-06 18:43

    The newest C++11 requires that:

    explicit operator bool() const;
    

    See C++11 27.5.5.4-1. The 'explicit' seems odd to me, though.

提交回复
热议问题