If we want to define a function that returns an array pointer, the dimension of the array must follow the name of the function, but after the function name is the formal parameter list, the formal parameter list should precede the dimension of the array. The function that returns an array pointer is as follows:
Type (*function (parameter_list)) [Dimension]
The declaration of the Func function below does not use a type alias:
int (*func (int i)) [10];
The tail return type can be used in C + + 11
Auto func (intint(*) [ten];
Using Decltype
If we know that the pointer returned by the function is pointing to which array, you can declare the return type using the Delctype keyword, for example, the following function returns a pointer to one of the two known quantity groups according to the difference in parameter I:
int odd[]={1,3,5,7,9}int even[]={0 ,2,4,6,8* ARRPTR (int i) { return (i%2)? &odd:&even; }
Arrptr uses the keyword Decltype to indicate that its return type is a pointer type, and that the pointer refers to an object that is consistent with the type of odd. Because odd is an array, ARRPTR returns a pointer to an array and a pointer containing 5 integers. There is one place to note:
Decltype is not responsible for it. The array type is converted to the corresponding pointer, so the result of the Decltype is an array, and to indicate that the ARRPTR return pointer must also add a * symbol to the function declaration.
Returns an array pointer