Why do we get an error when compiling the following code ?
class Pokemon { int hp; Pokemon(int _hp) : hp(_hp) {} public: void drain(Pokemon other) { other.hp -= 2; hp += 2; } }; int main() { Pokemon p1; Pokemon p2; p1.drain(p2); }
the constructor of Pokemon is not declared as public
Pokemon
public
the Pokemon class does not implement a default constructor
the drain method is using a call by value and does not modify Pokemon other
drain
Pokemon other
one instance of a Pokemon does not have access to the hp attribute of another instance because it's private
hp
private