2d-array size passing problem

I'm doing a program that involves 2d-array and I'm having a problem on passing it's size because i want the program to read the first two integers in the .txt file as the row and column of the array.

here's the program for my 2d-array class
1
2
3
4
5
6
7
8
9
10
class matrix{
	private:
	int r, c;
	int mtrx[r][c];
	
	public:
	void dispMtrx();
	void computeMtrx();
	void readMtrx(string fname);
};

when i try to compile it, the error says
invalid use of non-static data member
involving line 3. what seems to be the problem? :/ and what should i do to fulfill my goal (that is to make the program read the size of the 2d-array from the .txt file... because i need to read 2 matrices using 1 class)

oh, by the way... here's the function for reading the .txt file (in case you need to see it)
1
2
3
4
5
6
7
8
9
10
11
12
13
void matrix::readMtrx(string fname){
	cout << "[READING A MATRIX....]" << endl;
	ifstream fin;
	fin.open(fname);
	fin >> r >> c;
	while(!fin.eof()){
		for(int x=0; x<r; x++){
			for(int y=0; y<c; y++)
			    fin >> mtrx[x][y]
		}
	}
	fin.close();
}

also, please feel free to point out the errors you see from the code above. tnx in advance
Last edited on
if you want to use c-style arrays the sizes have to be calculable at compile time because that is when the memory is allocated for them.

You can get around it by using int* and new[]

Or by using the std::array class.
"int*" and "new[]"? do you mean dynamic array allocation using pointers?

uhm.. how do i do that? o.O
Topic archived. No new replies allowed.