Sorry, I missed the word "bidimensional" in your original post.
That compiler error is caused by the fact that your are allocating a
two dimensional array:
new char[a][5]
,
so it is not a pointer to a char, but
a pointer to a pointer to a char, i.e. it is
char**
rather than
char*
.
Making a variable inside a function
static
means that it will be created (and possibly initialized) the first time the function is called, and on subsequent calls of the function, it will retain the value it had previously.
The reason I suggested it here is the following. If you make this variable:
char buffer[64];
and then return
return buffer;
,
then the variable's life ends and it's memory is returned to the stack, so even though the caller has an address of the memory, it no longer contains the content it was given inside the function.
By making the variable static:
static char buffer[64]
,
we allow it to be returned in this way:
return buffer;
.
A static variable is alive for the entire length of the program (roughly) after it has been defined.
However, as I said, if you call the function more than once, and then try to use the char* you got from the first call, it will now contain the same value as that which you got from the second call, as they point to the same place.
As for returning by value an std::string, I simply suggesting this because std::string is basically an array of characters, but it looks after it's own data and can be copied so you can return it and thus avoid all the lifetime issues I have mentioned.
If your array is bidimensional, you can't return an std::string. However, perhaps you shouldn't use a bidimensional array, but a single dimensional array. Believe me, you can achieve the same results if you do it correctly. See here:
http://cplusplus.com/articles/G8hv0pDG/