int *image = new int[W][H]; -- is it wrong??
It will NOT compile. You should compile your code first, to know the answer of your question.
I think you want to do this:
//memory allocation
int **image = new int*[W];
for(size_t i = 0 ; i < W ; i++ )
image[i] = new int[H];
//use it as
for(size_t i = 0 ; i < W ; i++ )
for(size_t j = 0 ; j < H ; j++ )
image[i][j] = some_value;
int value = image[20][30]; //get value at (20,30) assuming 20 < W and 30 < H
//memory deallocation
for(size_t i = 0 ; i < W ; i++ )
delete [] image[i];
delete [] image;
But then why do all these when you've std::vector
? You could use it which will do all these nasty thing itself. Here is how you should be using std::vector
:
std::vector<std::vector<int> > image(W, std::vector<int>(H));
for(size_t i = 0 ; i < W ; i++ )
for(size_t j = 0 ; j < H ; j++ )
image[i][j] = some_value;
int value = image[20][30]; //get value at (20,30) assuming 20 < W and 30 < H