#include using namespace std ; class MyClass { public: explicit operator bool() const { // Return true if the object is in a valid state, false otherwise cout << "Inside bool." << endl ; return true; } }; int main() { MyClass obj; if (obj) { // Contextual conversion: explicit operator bool() is implicitly called // ... } bool b1 = static_cast(obj); // Explicit cast required // bool b2 = obj; // Error: explicit conversion not allowed in copy-initialization }