When compiling the following code:
void DoSomething(int Numbers[])
{
int SomeArray[] = Numbers;
}
the VS2005 compiler complains with the error C2440: 'initializing' : cannot convert from 'int []' to 'int []'
I understand that really it's trying to cast a pointer to an array which is not going to work. But how do you explain the error to someone learning C++?
Say that there are types and incomplete types:
struct A;
Is an incomplete type of a struct called A. While
struct A { };
Is a complete type of a struct called A. The size of the first is not yet known, while the size of the second is known.
There are incomplete class types like the above struct. But there are also incomplete array types:
typedef int A[];
That is an incomplete array type called A. Its size is not yet known. You cannot create an array out of it, because the compiler does not know how big the array is. But you can use it to create an array, only if you initialize it straight away:
A SomeArray = { 1, 2, 3 };
Now, the compiler knows the array is an int array with 3 elements. If you try to initialize the array with a pointer, the compiler will not be any more clever than before, and refuse, because that won't give it the size of the array to be created.