fork download
  1. #include <iostream>
  2.  
  3. class Player
  4. {
  5. private:
  6. int health;
  7. int mana;
  8. int attack;
  9. int defense;
  10. int speed;
  11.  
  12. public:
  13. Player()
  14. {
  15. health = 0;
  16. mana = 0;
  17. attack = 0;
  18. defense = 0;
  19. speed = 0;
  20. }
  21.  
  22. void attack()
  23. {
  24. std::cout << "You attack!\n";
  25. }
  26.  
  27. void defend()
  28. {
  29. std::cout << "You defend!\n";
  30. }
  31. };
  32.  
  33. int main()
  34. {
  35. Player player1;
  36. player1.attack();
  37. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:25:9: error: 'void Player::attack()' conflicts with a previous declaration
         }
         ^
prog.cpp:8:13: note: previous declaration 'int Player::attack'
         int attack;
             ^
prog.cpp: In constructor 'Player::Player()':
prog.cpp:17:20: error: invalid use of member function (did you forget the '()' ?)
             attack = 0;
                    ^
stdout
Standard output is empty