if() overloading

Let we have a Simple class. What should we overload in order for statements like this work:

Sample s;
if(s)
{
}
else
{
}

The real example cheking eof in streams:

ifstream in("somefile");
while(in)
{
     //do something
}
LVL 3
msterjevAsked:
Who is Participating?
 
codez80Connect With a Mentor Commented:
bool operator:


class X {
public:
   operator bool() const {
     return false; /* or maybe true!!! */
   }
};


good luck

codez80
0
All Courses

From novice to tech pro — start learning today.