Q:

Is this the correct implementation of a dynamically allocated 2d array

So i am tasked with the following question. I'm not sure if this is the appropriate way to implement this.
Write the implementation of init2DArray() so that it allocates memory for numRows then numCols and assigns each cell to value.
Additionally, have it print out an error statement(if applicable).
The class declaration is given.
#include <iostream>

class TwoDArray{
public:
    TwoDArray(){m_TwoDArray = NULL;};
    void init2DArray(int numRows, int numCols, int value);
private:
    int** m_TwoDArray;

};

This is my implementation
void TwoDArray::init2DArray(int numRows, int numCols, int value){
    m_TwoDArray = new int* [numRows];
    if(! m_TwoDArray)
        std::cout << "Error" << std::endl;
    for(int i = 0; i < numRows; i++){
        m_TwoDArray[i] = new int [numCols];
    }
    for(int i = 0; i < numRows; i++){
        for(int j = 0; j < numCols; j++){
            m_TwoDArray[numRows][numCols] = value;
        }
    }
}

Thanks for the help.

A:

m_TwoDArray[numRows][numCols] = value;

is not right. You end up accessing the array out of bounds, which will result in undefined behavior. That needs to be changed to:
m_TwoDArray[i][j] = value;

