While everyone else here seems hung up on (correctly) addressing your syntax (the trailing []
) I suspect your issue you've struggled with at present is how to pass a pointer-to-pointer-to-const-char. The original syntax you provided is wrong, but doing this:
char **names = new char *[numNames];
// populate names[]
MyMethod(names);
won't exactly solve your problem. You'll receive a "no matching function call" error because the parameter you're passing is of a specific type (pointer-to-pointer-to-char), while the function is expecting a non-trivially-convertable different type (pointer-to-pointer-to-const-char).
The simple fact is, you can't do it from char **
. See this question/answers for the reasons why, but the long and short of it is the types are simply not compatible. If you want to do this without changing that prototype you're going to have to do something like this:
int numNames = 5;
char **names = new char *[numNames];
// populate your names[], then...
const char **ro_names = new const char *[numNames];
std::copy(names, names+numNames, ro_names);
MyMethod(ro_names);
delete [] ro_names;
// clean up names[] elements, then...
delete [] names;
Hideous I know. You can clean it up considerably using a vector (which you should be using anyway, btw), but I kept the shuddering dynamics as they were what you started with.