With all of the fundamental types of C++, one can simply query:
if(varname)
and the type is converted to a boolean for evaluation. Is there
The C++11 approach is:
struct Testable
{
explicit operator bool() const
{ return false; }
};
int main ()
{
Testable a, b;
if (a) { /* do something */ } // this is correct
if (a == b) { /* do something */ } // compiler error
}
Note the explicit keyword which prevents the compiler from converting implicitly.