Possible Duplicate:
why isnt it legal to convert (pointer to pointer to non-const) to a (pointer to pointer to a const)
Hi I have the following code, but cannot wrap my head around why this doesn't work - I get an error saying "cannot convert from int** to const int**". However, if I change the first argument of printValues to be "const int *const * myArray", it all works fine. I know I probably shouldn't be using the one below anyway, but I don't understand why it doesn't compile at all. Can you not have a pointer to a pointer to a constant integer without declaring it constant in main()?
#include <iostream> int printValues(const int ** myArray, const long nRows, const long nCols) { for (long iRow = 0; iRow < nRows; iRow++) { for (long iCol = 0; iCol < nCols; iCol++) { std::cout << myArray[iRow][iCol] << " "; } std::cout << "\n"; } return 0; } int main() { const long nRows = 5; const long nCols = 8; int** myArray = new int* [nRows]; for (long iRow = 0; iRow < nRows; iRow++) { myArray[iRow] = new int [nCols]; } for (long iRow = 0; iRow < nRows; iRow++) { for (long iCol = 0; iCol < nCols; iCol++) { myArray[iRow][iCol] = 1; } } printValues(myArray, nRows, nCols); return 0; }