Defining 2d Array Crashes Program
Jun 25, 2014 at 8:15am UTC
I've got a class called Shop with x2 2d arrays in it. When I call the function to define the values of the arrays my program crashes. Am I defining the arrays incorrectly?
1 2 3 4 5 6
class Shop
{
public :
string shoparmor[5][6];
string shopweapon[3][8];
};
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 76 77 78 79 80 81 82 83
void setupshop()
{
//name, cost, DR, Defense, Str Req, Agi penalty
shop1.shoparmor[0][0] = { "Light Leather" };
shop1.shoparmor[0][1] = { "10" };
shop1.shoparmor[0][2] = { "1" };
shop1.shoparmor[0][3] = { "0" };
shop1.shoparmor[0][4] = { "0" };
shop1.shoparmor[0][5] = { "0" };
shop1.shoparmor[1][0] = { "Gambeson" };
shop1.shoparmor[1][1] = { "20" };
shop1.shoparmor[1][2] = { "2" };
shop1.shoparmor[1][3] = { "0" };
shop1.shoparmor[1][4] = { "0" };
shop1.shoparmor[1][5] = { "0" };
shop1.shoparmor[2][0] = { "Worked Leather" };
shop1.shoparmor[2][1] = { "50" };
shop1.shoparmor[2][2] = { "2" };
shop1.shoparmor[2][3] = { "1" };
shop1.shoparmor[2][4] = { "1" };
shop1.shoparmor[2][5] = { "0" };
shop1.shoparmor[3][0] = { "Branded Leather" };
shop1.shoparmor[3][1] = { "75" };
shop1.shoparmor[3][2] = { "3" };
shop1.shoparmor[3][3] = { "0" };
shop1.shoparmor[3][4] = { "0" };
shop1.shoparmor[3][5] = { "-1" };
shop1.shoparmor[4][0] = { "Cuir Bouilli" };
shop1.shoparmor[4][1] = { "100" };
shop1.shoparmor[4][2] = { "3" };
shop1.shoparmor[4][3] = { "1" };
shop1.shoparmor[4][4] = { "1" };
shop1.shoparmor[4][5] = { "-1" };
shop1.shopweapon[0][0] = { "Dagger" };
shop1.shopweapon[0][1] = { "1d6" };
shop1.shopweapon[0][2] = { "25" };
shop1.shopweapon[0][3] = { "Str" };
shop1.shopweapon[0][4] = { "7" };
shop1.shopweapon[0][5] = { "Percing" };
shop1.shopweapon[0][6] = { "Adaptive" };
shop1.shopweapon[0][7] = { "" };
shop1.shopweapon[1][0] = { "Axe" };
shop1.shopweapon[1][1] = { "1d6" };
shop1.shopweapon[1][2] = { "30" };
shop1.shopweapon[1][3] = { "Str" };
shop1.shopweapon[1][4] = { "7" };
shop1.shopweapon[1][5] = { "Slashing" };
shop1.shopweapon[1][6] = { "Aerodynamic" };
shop1.shopweapon[1][7] = { "" };
shop1.shopweapon[2][0] = { "Shuriken" };
shop1.shopweapon[2][1] = { "1d6" };
shop1.shopweapon[2][2] = { "50" };
shop1.shopweapon[2][3] = { "None" };
shop1.shopweapon[2][4] = { "6" };
shop1.shopweapon[2][5] = { "Slashing" };
shop1.shopweapon[2][6] = { "Finesse" };
shop1.shopweapon[2][7] = { "" };
shop1.shopweapon[3][0] = { "Meteor Gammer" };
shop1.shopweapon[3][1] = { "1d6" };
shop1.shopweapon[3][2] = { "50" };
shop1.shopweapon[3][3] = { "None" };
shop1.shopweapon[3][4] = { "7" };
shop1.shopweapon[3][5] = { "Crushing" };
shop1.shopweapon[3][6] = { "Chain Weapon" };
shop1.shopweapon[3][7] = { "" };
shop1.shopweapon[4][0] = { "Broadsword" };
shop1.shopweapon[4][1] = { "2d6" };
shop1.shopweapon[4][2] = { "85" };
shop1.shopweapon[4][3] = { "Str" };
shop1.shopweapon[4][4] = { "8" };
shop1.shopweapon[4][5] = { "Slashing" };
shop1.shopweapon[4][6] = { "Arming" };
shop1.shopweapon[4][7] = { "" };
}
1 2 3 4
void main()
{
setupshop();
}
Jun 25, 2014 at 8:24am UTC
Out of range array access:
1 2 3 4 5
string shopweapon[3 ][8];
//...
shop1.shopweapon[3 ][0] = //...
shop1.shopweapon[4 ][0] = //...
Jun 25, 2014 at 8:25am UTC
shopweapon
is going out of bounds from line 66 onward
Jun 25, 2014 at 8:31am UTC
All the shame. Thank you.
Topic archived. No new replies allowed.