The C++ standard I/O stream class ios
defines two overloaded operator !
and void*
that are used to check the stream's state.
For example:
ifstream fin("hello.txt");
if (fin) {} // ios::operator void*() is called
if (!fin) {} // ios::operator !() is called
However, I think two overloaded operators are overdid. Why not just one overloaded function operator bool()
?
It is likely because I/O stream classes were widely used before bool
became one of C++ keywords. In other words, keep them there just for backward compatibility.
If just for backward compatibility, why are they not marked as deprecated? If not for backward compatibility, then for what?