No, that part works fine, in fact from within the function, everything appears to be perfect, and I can even check the values in the array. But when the function returns, the address of filters_a has not even changed!
you need to pass the string filters_a by reference.
int explode(string src, char c, string out[]) // -> passing by value
int explode(string src, char c, string & out[]) // -> passing by reference
P.s : unless you are using array of strings, you really don't need to say
string out[] // in your parameter
string out // without [] would be fine
also I would suggest that you always use passing by reference when passing strings, and if you don't want to change the data in your string you would pass it with 'const'.
Edit: I'm sorry, what exactly are you trying to do?
int explode(string src, char c, string * out) // try this
edit: "string out[]" meaning you have an array of strings ... where its only a pointer to a string pointing to nothing yet till its goes into the function.
My program does compile, and explode works. From inside explode I can check the array elements, and all is fine. Once the function returns, accessing any element of the array crashes. And I have tried the following as arguments:
You are changing out to point to a new address. When you pass in filters_a, it continues to point to the old address which is not modified by the function.
To fix the problem, just change the function signature to this:
int explode(string src, char c, string*& out)
By passing out by reference, the function will modify filters_a.