I've been tasked with creating a class for a two dimensional dynamic array and I am stuck at a part where I need to create a member function which I can call upon to change a specific position in the 2D array to a value of my choosing.
class TwoD
{
public:
void setRowCol(int numRow, int numCol, double value);
TwoD();
TwoD(int row, int col);
void fillArray();
void outputArray();
private:
double** dArray = new double* [MaxRow];
int MaxRow;
int MaxCol;
};
TwoD::TwoD()
{
MaxCol = 3;
MaxRow = 3;
for (int i = 0; i < 3; i++)
{
dArray[i] = new double[3];
}
}
void TwoD::setRowCol(int numRow, int numCol, double value)
{
dArray[numRow][numCol] = value;
}
So the part I am having trouble with is the last part with the function setRowCol. I think that the problem is that it's not passing a 'deep' copy of the array but rather the original array itself.
Make the MaxRow as static variable & initialize it to appropriate value(3) before using it to create dArray.