fork download
  1. #include <iostream>
  2.  
  3. struct Monsters
  4. {
  5. int Damage;
  6. int PowerUp;
  7. int Monster_Strength;
  8.  
  9. // remaining members elided for brevity
  10.  
  11. Monsters( int d, int p, int ms ) : Damage(d), PowerUp(p), Monster_Strength(ms) {}
  12. };
  13.  
  14. bool operator== ( const Monsters& a, const Monsters& b ) // C++11
  15. {
  16. return a.Damage == b.Damage && a.PowerUp == b.PowerUp &&
  17. a.Monster_Strength == b.Monster_Strength ;
  18. }
  19.  
  20. bool operator!= ( const Monsters& a, const Monsters& b ) { return !(a==b) ; }
  21.  
  22. int main()
  23. {
  24. Monsters m11( 23, 2, 5 ) ; // *** note this - () instead of {}
  25. if( m11 == Monsters( 23, 2, 5 ) ) std::cout << "ok\n" ;
  26. if( m11 != Monsters( 23, -6, 5 ) ) std::cout << "ok\n" ;
  27. }
  28.  
Success #stdin #stdout 0s 2728KB
stdin
Standard input is empty
stdout
ok
ok