I am very worried...I have a project to turn in soon but my program suddenly decided to go crazy on me. Now, it crashes whenever I call a function.
I did a bit of research and it seems I may need a copy constructor and assignment operator, but it seems complicated because of the way my class is made, here is the example:
I only included the variables here
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
|
Player
{
private:
static const int SKILL_NUM=4;
static const int MAIN_ELEMENTAL_SKILLS=8;
//Basic information
string name;
string element;
string type;
int level;
int experience;
int totalExp;
int gold;
int itemCount;
int ID;
int statPoints;
int currentHealth;
int allyCount;
//Elemental experience (from using elemental skills)
int elementalExp[MAIN_ELEMENTAL_SKILLS];
//Weapon experience and levels
int swordsmanExp;
int swordsmanLevel;
int clericExp;
int clericLevel;
int hunterExp;
int hunterLevel;
int barbarianExp;
int barbarianLevel;
//Player stats
Stats stats;
Stats totalStats;
//Player skills
double weaponCombo;
Skills physical[SKILL_NUM];
Skills offensive[SKILL_NUM];
Skills defensive[SKILL_NUM];
//Equipment slots
Item *mainHand;
Item *offHand;
Item *head;
Item *body;
Item *feet;
Item *ring1;
Item *ring2;
animArrays screen;
}
|
So as you can see, it contains multiple other classes. Should I make a copy constructor for them, too?
But then another issue arises that I don't know how to deal with, you see, the
Item
objects use polymorphism. I don't know how this affects any of it, and I have absolutely no idea as to how I would go about making the copy constructor/assignment operator for them.
Side note, I was running this class (WITHOUT a copy constructor or assingment operator) and equating Player objects freely, sorting them and such, equaling them to each other. Do you think this is why my program now crashes so suddenly?
This is what I currently have, just the basic really, I don't know how to start working out the Item objects, or how they would be affected.
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
|
Player::Player(const Player& other)
{
name=other.name;
element=other.element;
type=other.type;
level=other.level;
experience=other.experience;
gold=other.gold;
itemCount=other.itemCount;
ID=other.ID;
statPoints=other.statPoints;
totalExp=other.totalExp;
allyCount=other.allyCount;
weaponCombo=other.weaponCombo;
currentHealth=other.currentHealth;
for(int i=0;i<MAIN_ELEMENTAL_SKILLS;i++)
elementalExp[i]=other.elementalExp[i];
for(int i=0;i<4;i++)
{
physical[i]=other.physical[i];
offensive[i]=other.offensive[i];
defensive[i]=other.defensive[i];
}
swordsmanExp=other.swordsmanExp;
swordsmanLevel=other.swordsmanLevel;
clericExp=other.clericExp;
clericLevel=other.clericLevel;
hunterExp=other.hunterExp;
hunterLevel=other.hunterLevel;
barbarianExp=other.barbarianExp;
barbarianLevel=other.barbarianLevel;
}
|