My personal choice would be to flatten the 2D array first and return a pointer to that, if some other container wasn't available.
I believe someone demonstrated this but it bears repeating:
Code:
#include <cstddef>
#include <cstring>
class stupidmatrix
{
public:
stupidmatrix (std::size_t rowheight, std::size_t colwidth):
_rows(rowheight),
_cols(colwidth),
_impl(new int [_rows*_cols])
//If you had an existing 2D-array, you could just allocate a new pointer like this,
//copy the data over, and then delete and reassign the old pointer. Try this assignment
//in a loop:
//newp[row*_rows+i] = oldp[row][i];
{
}
~stupidmatrix ()
{
delete[] _impl;
}
int * get ()
{
return _impl;
}
private:
int * _impl;
const std::size_t _rows;
const std::size_t _cols;
};
Not a complete example at all, but I think you should use or build a matrix class.