i am trying to make a type from one class carry over to another class and dont know how. i need to get "Hero player" into my Battle class so it can process the players health in a battle along with xp.
as the code is i get this error:
Battle.cpp||In member function 'void Battle::MainBattle()':|
Battle.cpp|5|error: 'player' was not declared in this scope|
||=== Build finished: 1 errors, 0 warnings ===|
Main.cpp
1 2 3 4 5 6 7 8 9 10 11
#include "Main.h"
int main()
{
Hero player;
player.setexp(0);
player.sethealth(50);
std::cout << "player starts with " << player.getexp() << " exp and " << player.gethealth() << " health \n\n";
return 0;
}
#include "Hero.h"
//get the Heroes health
int Hero::gethealth()
{
return health;
}
//get the heroes experience
int Hero::getexp()
{
return exp;
}
//set the heroes health
int Hero::sethealth(int newhealth)
{
health = newhealth;
return health;
}
//set the heroes experince
int Hero::setexp(int newexp)
{
exp = newexp;
return exp;
}
Hero.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
class Hero
{
public:
int getexp();
int gethealth();
int sethealth(int);
int setexp(int);
private:
int health;
int maxhealth;
int exp;
int newhealth;
};
Follow your compiler's errors. Looking at Battle.h, which Battle.cpp includes, no player is ever declared. However, it is declared within Main.cpp, local to main().