I want to evaluate an instance of some class in a boolean context. Or to be clearer, i want to define how the object reacts if its used directly in a boolean context.
Here an example:
class Foo
{
int state;
Foo(): state(1) {}
bool checkState()
{
return (state >= 0);
}
void doWork()
{
/*blah with state*/
}
};
int main()
{
Foo obj;
//while(obj.checkState()) //this works perfectly, and thats what i indent to do!
while(obj) //this is what want to write
obj.doWork();
return 0;
}
Ok, its just a nice to have :-), but is this possible at all? If yes, how?
Thanks!