Can't access a 2D array that I created in the constructor in the printMatrix class function. When I call the function in main with a simple cout << "test"; it will print that. If I try to print the values of matrixArray[][] it prints nothing and quits the program. Am I not referencing the 2d array correctly?
class matrix
{
int **matrixArray;
public:
int matrixSize = 0;
matrix(int matrixSize);
void printMatrix();
void makeMagicSquare();
};
matrix::matrix(int const matrixSize)
{
this->matrixSize = matrixSize ;
int** matrixArray = new int*[matrixSize];
for(int i = 0; i<matrixSize; i++){
matrixArray[i] = new int[matrixSize];
}
for(int row = 0; row < matrixSize ;row++)
{
for(int col = 0; col < matrixSize; col++)
{
matrixArray[row][col] =0;
cout << matrixArray[row][col] << " ";
}//End for Col
cout << endl;
}//End for Row
}
//printMatrix Function
void matrix::printMatrix(){
for(int row = 0; row < matrixSize;row++)
{
for(int col = 0; col < matrixSize; col++)
{
cout << "test" << " ";
//Not able to print from print function
cout << matrixArray[row][col] << endl;
}// end col
cout << endl;
}//end row
}