Why don't iostream objects overload operator bool?

前端 未结 3 1583
無奈伤痛
無奈伤痛 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:25

    This is an instance of the "safe bool" problem.

    Here is a good article: http://www.artima.com/cppsource/safebool.html .

    C++0x helps the situation with explicit conversion functions, as well as the change that Kristo mentions. See also Is the safe-bool idiom obsolete in C++11? .

提交回复
热议问题