fork download
  1. #include <iostream>
  2.  
  3. struct Car
  4. {
  5. int horsepower;
  6. friend bool operator == ( Car &lhs, Car &rhs ) ;
  7. };
  8.  
  9. bool operator == ( Car &lhs, Car &rhs )
  10. {
  11. return lhs.horsepower == rhs.horsepower;
  12. }
  13.  
  14. int main( int argc, char* argv[] )
  15. {
  16. Car a, b, c;
  17. a.horsepower = 80;
  18. b.horsepower = 135;
  19. c.horsepower = a.horsepower;
  20.  
  21. if( a == b )
  22. std::cout << "a and b same\n";
  23.  
  24. if( a == c )
  25. std::cout << "a and c same\n";
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
a and c same