I am attempting to create a two dimensional array depending on the users desired number of rows and columns. I am receiving an error of "use of undeclared identifier 'rows'". I googled and searched on stack overflow but was not able to find a scenario like this, I would like to know what am I doing wrong below is my code :
#include <iostream>
using namespace std;
class Matrix{
public:
int matrixDimensions[rows][columns];
void setMatrix(int x, int y){
rows = x;
columns = y;
}
int getMatrixDimensions(){
return rows;
return columns;
}
private:
int rows;
int columns;
};
int main(int argc, const char * argv[]) {
int a;
int b;
Matrix matrixObject;
cout << "Please enter the number of rows: " << endl;
cin >> a;
cout << "Please enter the number of columns: "<< endl;
cin >> b;
matrixObject.setMatrix(a, b);
cout << "The number of rows and columns are : " << matrixObject.getMatrixDimensions();
return 0;
}
Thank you all feedback is welcomed.I cannot use vectors, thank you for mentioning them but it is not an option here.