Reputation: 387
I state to be a beginner in C++. This is the first time I use classes and I think I made a mess with pointers. Until today I've always used the struct but with the private members I went haywire.
I need to create:
class Army{
private:
WarriorEl* lista;
int lungh = 0;
public:
Army();
....other methods.....
};
class WarriorEl{
private:
Warrior war;
WarriorEl* pun;
public:
WarriorEl();
WarriorEl(int health, int mana, int index, float experience);
....other methods.....
};
class Warrior{
private:
int health;
int mana;
int index;
float experience;
public:
Warrior();
Warrior(int health, int mana, int index, float experience);
....other methods.....
};
In compilation it's fine, but when I run the code it crashes when variables are initialized.
main: http://codepad.org/Hm5mhsJv
Army.h http://codepad.org/AHM0OTxQ
Army.cpp http://codepad.org/Uuql3Wud
WarriorEl.h http://codepad.org/o3Q1V3Gf
WarriorEl.cpp http://codepad.org/AumIpNdo
Warrior.h http://codepad.org/x52A66fF
Warrior.cpp http://codepad.org/F5QZxnH9
Upvotes: 0
Views: 82
Reputation: 1009
This error is seen when we try to write into some unallocated space.
Please check you loops and the corner cases to confirm there is no out-of-bounds access.
Upvotes: 1