Yes, it is inherited from C. Function:
void foo ( char a[100] );
The parameter will be configured as a pointer, and it will be as follows:
void foo ( char * a );
If you want to keep the type of the array, you must pass a reference to the array:
void foo ( char (&a)[100] );
C ++ '03 8.3.5 / 3:
... The type of function is determined using the following rules. The type of each parameter is determined from its own decl-specifier-seq and declarator. After determining the type of each parameter, any parameter of the type "array T" or "returning function T" is configured as a "pointer to T" or "pointer to a return function T", respectively ....
To explain the syntax:
Check the correctness of the "right left" rule in google; I found one description here .
It will be applied to this example as follows:
void foo (char (&a)[100]);
Start with id 'a'
'a' is
Move to the right - we will find ) so that we look in the opposite direction ( . When we move to the left, we go through &
'a' is a link
After & we get to the opening ( so that we turn again and look right. Now we see [100]
'a' is a reference to an array of 100
And we again turn the direction until we reach char :
'a' - reference to an array of 100 characters
Richard Corden Aug 25 '09 at 13:22 2009-08-25 13:22
source share