-
returning 2D arrays
i have a 2D array of ints. its a private member of my class and i want to keep it that way
Code:
class Class
{
private:
int array[10][10];
//...
};
the name of a 2D array is nothing more than a pointer to the first element of an array, which is in turn a pointer to the first element in its array.
array is a pointer to array[0] which is a pointer to array[0][0].
so i make a function that returns a 2D pointer.
Code:
int ** Class::function()
{
return array;
}
but i always end up with an error like this:
" cannot convert int[10][10] to int ** "
now, if a 2D array is just a double pointer, why wont this work? how can i get to this outside of the class without making it public?
-
well, i wasnt planning on giving it full access to the pointer, i was going to make it a const... what i was saying was only an example.
but thanks, that worked...
-
Thanks, Salem, for answering that question so well. I thought one would simply line up asterisks till the cows came home :P