Hi. First time user here. I'm practicing using dynamic 2D arrays. I'm also using classes, so the matrix is a member of the class. I have code to allocate memory for a matrix and code to have the user initialize the matrix from the keyboard.
After the user is prompted to enter values, you can enter all the values needed but after the last row is filled out, the program crashes. The program is crashing before the function 'fillMatrix()' finishes, because I wrote a line of code to print something to the screen at the end of the function, just to try and pinpoint where the program was crashing, and it was not printed to the screen.
Anyone see anything wrong with my code? Thanks in advance!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
void matrixType::allocateMatrix()
{
matrixData = newint* [numRows];
for (int x = 0; x < numRows; x++)
matrixData[x] = newint[numColumns];
}
void matrixType::fillMatrix()
{
allocateMatrix();
cout << "Enter values for the " << numRows << "x" << numColumns << "matrix:\n";
for (int row = 1; row <= numRows; row++)
{
for (int column = 1; column <= numColumns; column++)
cin >> matrixData[row][column];
}
}