From: Richard Haney <rfhaney@ya...> - 2006-06-12 20:24:35
More to the point about the supposed definition of operator bool() in
template class basic_istream (in header file <istream> -- mingw
distribution) is that, upon reexamination, it appears that bool() is
actually defined in a nested class "basic_istream<_CharT,
_Traits>::sentry" of class basic_istream<_CharT, _Traits>. I didn't
know there was any such thing as a nested class in C++, but it looks
like there is (upon comparison of the syntax with the Internet document
entitled "Working Draft, Standard for Programming Language C++"). I
don't know what the visibility characteristics of such a bool()
So it looks like maybe Greg Chicares is right about the implicit
conversion via std::basic_ios::operator!().
Maybe someone can clarify this.
On the other hand, if the bool() operator is effectively defined
automatically as a member also of class basic_istream<_CharT, _Traits>,
then it looks like it gets inherited by class basic_ifstream<_CharT,
_Traits> (note the "f") and that ifstream is defined by typedef as
basic_ifstream<char> (I'm not sure what happens with the omitted second
template argument; this seems to be a matter of C++ specs more recent
than the versions I've studied).
So it looks like __maybe__ the bool() operator instantiated in
basic_istream<char>::sentry from the template nested class
basic_istream<_CharT, _Traits>::sentry is the cast operator that gets
executed in the expression "(bool)getline(is,linebuf)".
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around