Why is while( cin ) valid?

cin is defines as: extern istream cin;
which means cin is an object, but while( ? ), here the type of the ? should be bool, right? So how does an object be transformed into a bool?

I defined one class by myself to test whether other objects could work properly, and the result shows they cannot. See the following example:

class Hello
{
public :
Hello(int var) : a(var) {}

private:
int a;
};

Hello h(0);
while ( h ); //error: could not convert "obj" to "bool"

So could anybody help explain how does while( cin ) work properly?
Thx in advance!
a stream object can be casted to a void* (ios's member operator void*) - the value returned is a null pointer if the stream has some error flag set.
Topic archived. No new replies allowed.