I'm writing a class which has dynamic two-dimensional array of integers as a field - most imporant part of it, short access time is preferable. I want to declare it in header file,
//Grid.h
class Grid{
int ** array;
}
however the size and contents of it are yet to be defined in constructor implemented in cpp file (propably a read from ini file).
I'm not sure if declaring a int **array pointer in header and assigning later dynamically array to it with use of
array = new int*[x];
for(i=0;i<x;i++){
array[i] = new int [y];
}
will result in creating an array that will be accessible and cause no trouble in other functions calling directly to field of array[i][j] in their definitions (or other less obvious errors), however it's granted that before mentioned functions start calling in, it will and has to be defined already.
My question - it this the valid and efficient way to do it? I'll accept any other ideas.
Yes, I've heard of "vector" class but I'm not sure about it's efficiency or read-and-write vs integer array performance. Vectors are flexible in size, but I don't need it - my array once set, will have fixed size.
Propably I'm just too used to Java-style int[][] array code.