"ragged arrays" in C/C++ are accessed though double indirection:
char** raggedArray;To pass such a beast by reference you just need "triple indirection" - a point to (a pointer to a pointer).
A ragged array is an array of pointers. Each of the elements points can point to a 1 dimentional array (of different lengths). So a pointer to the ragged array will work to pass this by referance:
CODE
int func(char ***PtrRaggedArray) {
(*ptrRaggedArray)[1] = new char[10];
...etc...
}
you can simplify the syntax using a typedef:
typedef char ** RaggedArray;
then the function becomes:
CODE
int func(RaggedArray &PtrRaggedArray) {
ptrRaggedArray[1] = new char[10];
...etc...
}
here is my little working example:
CODE
#include <cstring>
#include <iostream>
typedef char ** RaggedArray;
void func(char ***ptrToRaggedArray);
void foo(RaggedArray & array);
int main() {
char **ptr;
ptr = new char*[2];
func(&ptr);
foo(ptr);
std::cout << "ptr[0]: " << ptr[0] << std::endl;
std::cout << "ptr[1]: " << ptr[1] << std::endl;
delete[] ptr[0];
delete[] ptr[1];
return 0;
}
void func(char ***ptrToRaggedArray) {
(*ptrToRaggedArray)[0] = new char[100];
strcpy((*ptrToRaggedArray)[0], "Hello World!");
return;
}
void foo(RaggedArray & array) {
array[1] = new char[100];
strcpy(array[1], "Hello Nurse!");
return;
}