fork download
  1. #include <iostream>
  2.  
  3. struct Monsters
  4. {
  5. public:
  6. int Damage;
  7. int PowerUp;
  8. int Monster_Strength;
  9. int hp;
  10. int lvl;
  11. int money;
  12. int defense;
  13. };
  14.  
  15. #include <tuple>
  16.  
  17. bool operator== ( const Monsters& a, const Monsters& b ) // C++11
  18. {
  19. static const auto to_tuple = [] ( const Monsters& m )
  20. {
  21. return std::make_tuple( m.Damage, m.PowerUp, m.Monster_Strength, m.hp,
  22. m.lvl, m.money, m.money, m.defense ) ;
  23. };
  24. return to_tuple(a) == to_tuple(b) ;
  25. }
  26.  
  27. // principle of least surprise
  28. bool operator!= ( const Monsters& a, const Monsters& b ) { return !(a==b) ; }
  29.  
  30. int main()
  31. {
  32. Monsters m11 = { 23, 2, 5, 8, 19, 7, 9 } ;
  33. if( m11 == Monsters{ 23, 2, 5, 8, 19, 7, 9 } ) std::cout << "ok\n" ; // C++11
  34. if( m11 != Monsters{ 23, 2, 5, -9, 19, 7, 9 } ) std::cout << "ok\n" ; // C++11
  35. }
  36.  
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
ok
ok