Since this is a question about C++:
Do not use C-style arrays or pointers (neither for 1D nor 2D arrays). Use the C++ data types, such as vector
:
vector image(W * H); // 1D array
vector > image(W, vector(H)); // “2D” nested array.
This requires the vector standard header.