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 the Josuttis book for more information (p. 600 if you’re interested), and it turns out that the iostream objects actually overload operator void*. It returns a null pointer when the stream is bad (which can be implicitly converted to false), and a non-null pointer otherwise (implicitly converted to true). Why don’t they just overload operator bool?
In this answer I talk about using a std::ifstream object’s conversion to bool to
Share
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
explicitconversion functions, as well as the change that Kristo mentions. See also Is the safe-bool idiom obsolete in C++11? .