c++ convert class to boolean
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 … Read more