hey im working on a random monster generator and im getting a lil problem with my GetName() function and list something about it not being able to access class ENTITY.. ill post the code and the actual error if someone can help it would be greatly appreciated
i also havent set up the constructos yet idk if thats part of the problem or not
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
//entity.h
class ENTITY
{
private:
char name[32];
int gold;
int exp;
int health;
int maxhealth;
int mana;
int maxmana;
public:
bool SetName(char* newname);
char* GetName();
void SetGold(int newgold);
void AddGold(int amount);
void SpendGold(int amount);
int GetGold();
void SetExp(int newexp);
void AddExp(int amount);
int GetExp();
void SetHealth(int newhealth);
void AddHealth(int amount);
void LoseHealth(int amount);
int GetHealth();
void SetMaxHealth(int newmaxhealth);
int GetMaxHealth();
void SetMana(int newmana);
void AddMana(int amount);
void LoseMana(int amount);
int GetMana();
void SetMaxMana(int newmana);
int GetMaxMana();
};
|
Entity.cpp
there are more functions in this file but these 2 are relevant to the problem im having
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
bool ENTITY::SetName(char *newname)
{
if(strlen(newname) == 0)
return false;
if(strlen(newname) > 32)
return false;
strcpy(name,newname);
return true;
char* ENTITY::GetName()
{
return name;
}
}
|
battle.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
// BATTLE
#include "Library.h"
bool Battle(PLAYER* player,MONSTER* list,int count)
{
while (player->GetHealth() > 0)
{
// player goes first
cout << "You Clecnh Your " << player->GetWeapon()->GetName() << "tightly and face the enemy.\n\n";
//display enemy count
if (count == 1)
{
cout << "The" << list->GetName() << "stares at you, ready to attack.\n";
Wait();
}
else
{
cout << "Enemies\n";
for (int loopname = 0; loopname < count; loopname++)
{
if(list[loopname].GetHealth() > 0)
{
cout << list->name[loopname].GetName();
// output status effect
// goblin - poisoned
}
}
Wait();
}
// display player stats
cout << player->GetName() << endl;
//health / maxhealth. mana /maxmana
cout << "Health" << player->GetHealth() << " / " << player->GetMaxHealth() << endl;
cout<< "Mana" << player->GetMana() << " / " << player->GetMaxMana() << endl;
cout << "1: Attack\n";
cout << "2: Spell\n";
cout << "3: Item\n";
//
//action?
//check action
// is enemy dead?
//enemies turn
if (count == 1)
{
// have enemy fight
}
else
{
// loop
for (int loop = 0; loop < count; loop++)
{
// list[loop]
}
}
}
cout << " Thou hast been destroyed.\n\n";
return false; // you died
}
|
i also have a library header which has my monster.h/cpp and my player.h/cpp here are the errors
im doing a tutorial on making it but the error didnt happen to the person in the tutorial...
i know this is alot to read... here's the errors.....
5 IntelliSense: member "ENTITY::name" (declared at line 5 of "c:\users\x d y n a s 7 y\desktop\afternoon\runes of sarnac 2.0\runes of sarnac 2.0\Entity.h") is inaccessible c:\users\x d y n a s 7 y\desktop\afternoon\runes of sarnac 2.0\runes of sarnac 2.0\battle.cpp 26
4 IntelliSense: expression must have class type c:\users\x d y n a s 7 y\desktop\afternoon\runes of sarnac 2.0\runes of sarnac 2.0\battle.cpp 26
Error 2 error C2248: 'ENTITY::name' : cannot access private member declared in class 'ENTITY' c:\users\x d y n a s 7 y\desktop\afternoon\runes of sarnac 2.0\runes of sarnac 2.0\battle.cpp 26