fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class my_bool
  5. {
  6. private:
  7. bool value;
  8. public:
  9. my_bool(bool value) : value(value) {}
  10. operator bool() { return value; }
  11.  
  12. bool operator == (bool val)
  13. {
  14. return this->value == val;
  15. }
  16. };
  17.  
  18. int main()
  19. {
  20. my_bool a = true;
  21. bool b = true;
  22. bool c = false;
  23.  
  24. if (a == b)
  25. cout << "a==b: true" << endl;
  26. else
  27. cout << "a==b: false " << endl;
  28.  
  29. if (a == c)
  30. cout << "a==c: true" << endl;
  31. else
  32. cout << "a==c: false " << endl;
  33.  
  34. if (a)
  35. cout << "a is: true" << endl;
  36. else
  37. cout << "a is: false " << endl;
  38. return 0;
  39. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
a==b: true
a==c: false 
a is: true