Ok, so I'm writing a matrix program that'll do basic function such as addition and multiplication. Right now, I'm creating the object matrix, and I'm having trouble creating a 2D array. The error is error: declaration of 'mtrix' as multidimensional array must have bounds for all dimensions except the first.
Here's the header
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#ifndef MATRIX_H
#define MATRIX_H
class matrix
{
public:
matrix(int numRows, int numCols);
virtual ~matrix();
void setRowValues(int rowIndex, int ** values[]);
void setColValues(int colIndex, int ** values[]);
int rowCount, colCount, mtrix[][];
protected:
private:
};
#endif // MATRIX_H
"mtrix[][]" is not allowed. Only one dimension can be left variable.
If you want to decide both at runtime, you'll have to declare dynamically:
1 2 3 4 5 6 7 8
int **mtrix; // Declaration of a pointer to a pointer to an int
// Random code in between
mtrix = newint*[numRows];
for (int i = 0; i < numRows; ++i) {
matrix[i] = newint[numCols];
}
// ...
matrix[i][j] = ...;
Interpretation
mtrix is a pointer to/an array of pointers to/arrays of ints.
mtrix[i] is a pointer to/an array of ints.
mtrix[i][j] is an int