I am having a problem copying data members from an inherited class to the base class. All of the data is copied except the container data.
#ifndef NPC_H
#define NPC_H
/*
* Basic parent to all other NPC types.
* NOTICE: player is considered an NPC type
*/
enum CLASS_TYPE{
CT_CLERIC = 0,
CT_MAGICUSER,
CT_FIGHTER
};
class NPC
{
private:
string name;
CLASS_TYPE npcclass;
int level;
int strength;
int intelligence;
int wisdom;
int dexterity;
int constitution;
int charisma;
int armorclass;
int hitpoints;
int maxhp;
int gold;
int experience;
int maxxp;
int deathray;
int poison;
int magicwands;
int paralysis;
int turntostone;
int dragonbreath;
int rods;
int staves;
int spells;
WEAPON weapon;
ARMOR armor;
SHIELD shield;
bool hasshield;
bool istwohanded;
ITEM* inventory[15];
vector<SPELL> castableSpells;
public:
// class constructor
NPC();
// class destructor
~NPC();
void DisplayStats();
string GetName();
void SetName(string newname);
CLASS_TYPE GetClass();
void SetClass(CLASS_TYPE newnpcclass);
int GetLevel();
void SetLevel(int amount);
int GetSTR();
void SetSTR(int amount);
int GetINT();
void SetINT(int amount);
int GetWIS();
void SetWIS(int amount);
int GetDEX();
void SetDEX(int amount);
int GetCON();
int SetCON(int amount);
int GetCHR();
void SetCHR(int amount);
int GetAC();
int SetAC(int amount);
int GetHP();
void SetHP(int amount);
void AddHP(int amount);
void LoseHP(int amount);
int GetMHP();
void SetMHP(int amount);
int GetGold();
void SetGold(int amount);
void AddGold(int amount);
void LoseGold(int amount);
int GetXP();
void SetXP(int amount);
void AddXP(int amount);
void LoseXP(int amount);
int GetMXP();
void SetMXP(int amount);
WEAPON* GetWeapon();
void SetWeapon(WEAPON newweapon);
ARMOR* GetArmor();
void SetArmor(ARMOR newarmor);
SHIELD* GetShield();
void SetShield(SHIELD* nshield);
bool GetIsTwohanded();
void SetIsTwohanded(bool yesno);
bool AddInventory(ITEM* item);
ITEM** GetInventorylist();
void AddSpell(SPELL *newspell);
vector<SPELL>* GetSpellList();
void SetSavingsThrows(int svOne, int svTwo, int svThree, int svFour, int svFive);
};
#endif // NPC_H
#ifndef MAGICUSER_H
#define MAGICUSER_H
#include "npc.h" // inheriting class's header file
/*
* No description
*/
class MAGICUSER : public NPC
{
public:
// class constructor
MAGICUSER();
// class destructor
~MAGICUSER();
};
#endif // MAGICUSER_H
#include "Library.h"
#include "magicuser.h" // class's header file
// class constructor
MAGICUSER::MAGICUSER()
{
SetName("Magic-User"); // name
SetClass(CT_MAGICUSER); //npcclass
SetLevel(1); //level
SetSTR(8); //strength
SetINT(17); //intelligence
SetWIS(11); //wisdom
SetDEX(16); //dexterity
SetCON(14); //constitution
SetCHR(9); //charisma
SetHP(4); // hitpoints
SetMHP(4); // maxHP
SetGold(200); //gold
SetXP(0); //xp
SetMXP(2000);
SetSavingsThrows(13, 14, 13, 16, 15);
WEAPON* wp = GetWeapon();
wp->SetName("Dagger");
wp->SetDamage(4);
wp->SetIsTwohanded(false);
SetIsTwohanded(wp->GetIsTwohanded());
ARMOR* ar = GetArmor();
ar->SetName("Cloth Armor");
ar->SetAC(2);
SHIELD* sh = GetShield();
sh->SetName("No Shield");
sh->SetAC(0);
SetAC((9 - ar->GetAC()) - sh->GetAC()); //armorclass
MAGICMISSILE magicmissile;
AddSpell(&magicmissile); //<- NOTICE: in base class vector is empty
}
// class destructor
MAGICUSER::~MAGICUSER()
{
// insert your code here
}
Now all of the Gets/Sets are appropriate to the data members. one returns a copy of the value, and one sets the value to an amount of the correct type. NOTICE: the last data member in the NPC class is a container. When I create an instance of a MAGICUSER class it comes with a spell added to the vector. However, the base class castableSpells.size() = 0;
How could I add that spell when I copy the MAGICUSER to the NPC class?
NPC player;
MAGICUSER mu;
player = mu;
I have read about operator overloads and handle classes in C++ PRIMER 4th ed. but I'm getting lost really. any advice?.