I have the following function in C++ :
char** f()
{
char (*v)[10] = new char[5][10];
return v;
}
Visual studio 2008 says the following:
error C2440: 'return' : cannot convert from 'char (*)[10]' to 'char **'
What exactly should the return type to be, in order for this function to work?
char**is not the same type aschar (*)[10]. Both of these are incompatible types and sochar (*)[10]cannot be implicitly converted tochar**. Hence the compilation error.The return type of the function looks very ugly. You have to write it as:
Now it compiles.
Or you can use
typedefas:Ideone.
Basically,
char (*v)[10]defines a pointer to achararray of size 10. It’s the same as the following:So your code becomes equivalent to this:
cdecl.orghelps here:char v[10]reads asdeclare v as array 10 of charchar (*v)[10]reads asdeclare v as pointer to array 10 of char