How to use 2-dimentions arry in class

Hi everybody. I am trying to compile this code. But I have about 16 errors. This is the first time to use class in array. Can anybody help?

#include <iostream>
using namespace std;

class Squar
{
public:

int row;
int col;

int numRow;
int numCol;

int cell[numRow][numCol];


void fill (int cellF[numRow][numCol]); //fill


void print (int cellF[numRow][numCol]); // Print

};

int main()
{

cout<< " ----------------------------" << endl;

cout << endl << endl;


Squar squar;

squar.row = 0;
squar.col = 0;
squar.numRow = 0;
squar.numCol = 0;
squar.cell;

squar.fill(cell);
squar.print(cell);

cout << endl << endl;


return 0;
}

void Squar::fill (int cellF[numRow][numCol]) {
for ( row = 1; row < numRow; row++)
{
for ( col = 1; col < numCol ; col++)
{
cellF[row][col] = 0;
}
}
}


void Squar::print (int cellF[numRow][numCol]) // Print
{

for ( row = 1; row < numRow ; row++)
{
cout << '\n' << '\n' << '\n' << '\n';

for ( col = 1; col < numCol ; col++)
{
cout << '\t' ;
cout << row << col;
}
}

cout << endl << endl;
}
Last edited on
Lines 11-12: numRow, numCol are uninitialized variables (garbage).

Line 14: How big do you think your array is if numRow and numCol are garbage?

Line 38: This does nothing.

Line 40-41: It's not necessary to pass cell as an argument since it's a member variable.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.

Topic archived. No new replies allowed.