Я пытался сделать простую текстовую игру про покемонов на с ++.Я создал класс для pokemon, а затем в моем pokemain.cpp попытался вывести hp из charmander.Когда я пытаюсь запустить свой pokemonmain.cpp, он говорит, что charmander не был объявлен.Я уверен, что это глупый вопрос, но я не могу найти ответ на него.
Вот мой код.
//class named stats
#include <iostream>
using namespace std;
class pokemon
{
int health, damage;
public:
pokemon (int,int);
int hp()
{
return (health);
}
int dmg()
{
return (damage);
}
};
pokemon::pokemon (int hp, int dmg)
{
health = hp;
damage = dmg;
pokemon charmander (25,3);
pokemon bulbasaur (20,4);
pokemon squirtle (30,2);
cout<<" Charmander has "<<charmander.hp()<<" hp and "<<charmander.dmg()<<" damage.\n";
cout<<" Bulbasaur has "<<bulbasaur.hp()<<" hp and "<<bulbasaur.dmg()<<" damage.\n";
cout<<" Squirtle has "<<squirtle.hp()<<" hp and "<<squirtle.dmg()<<" damage.\n";
}
//pokemain.cpp
#include <iostream>
#include "stats.h"
using namespace std;
int main()
{
cout<<charmander.hp();
return 0;
}