I have an array within a class as a private member. I am trying to make a constructor to intilize this array, but I can only seem to make a new array within the constructor = useless. I need to find out how to use my array that is a private data member. Here's my code maybe I did something wrong since I haven't done this in awhile. Checked the forums kinda vague.
1 2 3 4 5 6 7 8 9 10 11 12
class PlayerMap
{
private:
int tileValue[];
int row;
int column;
int playerLocation;
int mapPath[];
bool mapTiles[5][6];
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
int row = 0;
int column = 0;
row = 5;
column = 6;
bool mapTiles[row][column]; // x = 5 y = 6
int tileValue[30] = {0};
int playerLocation = 0;
playerLocation = 17;
int counter = 0;
int mapcounter = 0;
int mapPath[] = { 1,2,6,8,9,11,12,15,16,17,18,19,20,21,23,25,29 }; // 17 total, 0-16 array
see I have quite a few arrays. One multi dimensional bool, Two intgers.
This is the only code I could get to work, but this won't do because it doesn't update the data members it only creates new arrays within the constructor which will go out of scope when it ends. Any help would be great. Thank you
If you can make this more efficient that would be great. Thanks
So, the problem is that you don't know how to initialize the array, or that you want the array to have a size defined at run time? memset(this->mapTiles,0,5*6*sizeof(int));
for the former.
[Code removed.]
EDIT: Damn. What a fool. Why didn't I ever think of that?
int mapPath[] = { 1,2,6,8,9,11,12,15,16,17,18,19,20,21,23,25,29 };
doing this creates a new array. It doesn't update the member. I need these values to be given to the data member array.
bool mapTiles[5][6];
I need a bool multi-dimensional array which should be defined & intilized in the constructor. 5 and 6 are just variables I picked I'd prefer if I didn't need to chose them till the constructor, but the compilers say the member needed bounds so I added 2 numbers.
// data member
bool mapTiles;
// in constructor
bool* mapTiles = newbool[row][column];
Gives me a error
PlayerMap::column' cannot appear in a constant-expression
I've tried many different things but it still isn't working. I even broke out my old C++ book and cannot seem to find out how to set attributes to a multi dimensional data member which is all I really want. I solved the other problems using the books.