First, let me say that I've tried Googling this multiple times, but only seem to find info on passing an array from main to a function, which I'm not having a problem with. My problem is when I pass an array to a function, then try to pass the array from that function to another function. Here is a simplified version of my problem:
#include "stdafx.h"
void function1(int);
void function2(int);
void function1(int intArray[2][3])
{
// do some work on the array
function2(intArray); // error C2664: 'function2' : cannot convert parameter 1 from 'int [][3]' to 'int'
}
void function2(int intArray[2][3])
{
// do some work on the array
}
int _tmain(int argc, _TCHAR* argv[])
{
int intArray[2][3];
function1(intArray);
function2(intArray); // same code, no errors with this line
return 0;
}
I'm guessing that this has something to do with pointers which I'm still having a bit of difficulty with. As I understand it, the array is not actually passed, but a pointer to it is. But then why is there a problem passing that pointer from function1 to function2? Is this what's called array decay? Why does the function call work fine in the main function but not in function1?