I'm using a library which requires a function with a void*
pointer as a parameter. I have a 2D string array and I want to pass that array through that parameter and extract it inside the function. I successfully passed the array as a pointer but I don't know how to convert that pointer back to my array.
This is my current code:
String str_array[100][10];
int callback(void* data) {
String* str_array_ptr[100][10] = (String* [100][10])data;
(*str_array_ptr)[0][0] = "text";
return 0;
}
void test() {
callback(&str_array);
}
However, when compiling, I obtain the following error message:
error: ISO C++ forbids casting to an array type 'String* [100][10]' [-fpermissive]
PS: I'm trying to use the SQLite library's sqlite3_exec()
function and store the result of a "SELECT SQL query" into a 2D string array.
String
is not a standard C++ type. In C++ we avoid C-style arrays, raw pointers, void pointers, and casts.String* [100][10]
is a 100x10 array of pointers toString
. If you need a pointer to an array, the best option is to usetypedef
.