fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct foo{
  5. bool operator==(bool val) const {
  6. cout << "foo::operator== ";
  7. return false;
  8. }
  9. bool operator!()const{
  10. cout << "foo::operator!";
  11. return reinterpret_cast<intptr_t>(this)/sizeof(this) / 2 == 0;
  12. }
  13. };
  14.  
  15. bool operator==(bool lhs,const foo &rhs){
  16. cout << "global operator==";
  17. return true;
  18. }
  19.  
  20. foo Function(){
  21. return foo();
  22. }
  23.  
  24. int main() {
  25. if(false == Function()){
  26. cout << "true" <<endl;
  27. }else{
  28. cout <<"false" << endl;
  29. }
  30. if(Function() == false){
  31. cout << "true" <<endl;
  32. }else{
  33. cout <<"false" << endl;
  34. }
  35. if(!Function()){
  36. cout << "true" <<endl;
  37. }else{
  38. cout <<"false" << endl;
  39. }
  40. return 0;
  41. }
Success #stdin #stdout 0s 2728KB
stdin
Standard input is empty
stdout
global operator==true
foo::operator== false
foo::operator!false