class Array2D {
public:
vector<int> v;
int nc;
Array2D(int NR, int NC) : v(NR*NC), nc(NC) {}
int* operator[](int r) { return &v[r*nc]; }
};
int main()
{
Array2D array2d(2, 3);
array2d[0][0] = 1;
array2d[1][2] = 6;
}
This allows you to create a class that will function like a 2D array. It’s fast and the data is contiguous.