I am writing a program to do simple matrix operations. but i want the dimensions of the matrix to be fed by the user. the code below, gives the following error during compile time...
`cols' cannot appear in a constant-expression
cout << "Number of rows:";
int r;
cin >> r;
cout << "Number of columns:";
int c;
cin >> c;
const int rows=r;
const int cols=c;
// Assign dimensions
float* mat1[rows][cols]; float* mat2[rows][cols]; float* mat3[rows][cols];
mat1= new float [rows][cols];
mat2= new float [rows][cols];
mat3= new float [rows][cols];
it works fine if they are 1 dimensional arrays, so why doesnt it compile if i use 2 dimensions. please help.
2007-03-21
15:44:08
·
2 answers
·
asked by
aswan k
1
in
Computers & Internet
➔ Programming & Design