I'm new to C++ and I'm practicing inheritance and I typed the code below. In Squirtle.cpp, visual studio is telling me that newHp, newLevel, newExperience and newAttack are all undefined. Why is this the case? How do I fix it? I've looked up other examples here such as this but I guess they would't get an error because both their base and child constructors are in the same file?
****Pokemon.h****
#ifndef _POKEMON_
#define _POKEMON_
#include <string>
#include <iostream>
using namespace std;
class Pokemon {
//Members
private:
int hp;
int level;
int experience;
int attack;
//Member functions
public:
Pokemon(int newHp, int newLevel, int newExperience, int newAttack);
virtual ~Pokemon();
int getHp();
int getAttack();
void setHp(int newHp);
void setAttack(int newAttack);
void physicalAttack(Pokemon &target);
};
#endif
****Pokemon.cpp****
#include "Pokemon.h"
Pokemon::Pokemon(int newHp, int newLevel, int newExperience, int newAttack)
{
hp = newHp;
level = newLevel;
experience = newExperience;
attack = newAttack;
}
Pokemon::~Pokemon()
{
}
int Pokemon::getHp()
{
return hp;
}
int Pokemon::getAttack()
{
return attack;
}
void Pokemon::setHp(int newHp)
{
hp = newHp;
}
void Pokemon::setAttack(int newAttack)
{
attack = newAttack;
}
void Pokemon::physicalAttack(Pokemon &target)
{
target.setHp(target.getHp() - getAttack());
cout << "Dealt " << getAttack() << "damages to target! Hp is now at " << target.getHp() << "!";
}
****Squirtle.h****
#include "Pokemon.h"
#ifndef _SQUIRTLE_
#define _SQUIRTLE_
class Squirtle :Pokemon{
//members
private:
int mana;
//member functions
public:
Squirtle(int newMana);
int getMana();
void setMana(int newMana);
void freeze(Pokemon &target);
};
#endif
****Squirtle.cpp****
#include "Squirtle.h"
Squirtle::Squirtle(int newMana):Pokemon(newHp, newLevel, newExperience, newAttack)
{
mana = newMana;
}
int Squirtle::getMana()
{
return mana;
}
void Squirtle::setMana(int newMana)
{
mana = newMana;
}
void Squirtle::freeze(Pokemon &target)
{
setMana(getMana() - 1);
target.setAttack(0);
cout << "Squirtle has frozen the target! Its attack is now reduced to 0!";
}