I am having a problem passing a non const 2D array of pointers as const argument for a function. But I am getting an error. I don't understand why.
// Online C++ compiler to run C++ program online
#include <iostream>
void test(const int *arrayPtr[][10]){}
//void test(int * const arrayPtr[][10]){//Works DO NOT USE //}
int main() {
int *arrayPtr[10][10] = {};
test(arrayPtr);
std::cout <<"done" << std::endl;
return 0;
}
g++ /tmp/JYRlXRFoja.cpp /tmp/JYRlXRFoja.cpp: In function 'int main()': /tmp/JYRlXRFoja.cpp:11:7: error: cannot convert 'int* (*)[10]' to 'const int* (*)[10]' 11 | test(arrayPtr);
| ^~~~~~~~
| |
| int* (*)[10] /tmp/JYRlXRFoja.cpp:5:42: note: initializing argument 1 of 'void test(const int* (*)[10])'
5 | void test(const int *arrayPtr[][10]){
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~