-
Hence, the form of a function that returns a pointer to an array is:
Type (*function(parameter_list))[dimension]
C++11:
trailing return type:
auto func(int) -> int(*) [10];
Using decltype:
int odd[] = {1,3,5,7,9};
int even[] = {0,2,4,6,8};
// returns a pointer to an array of five int elementsdecltype(odd) *arrPtr(int i)
-
A parameter that has a top-level const is indistinguishable from one without a top-level const:
Record lookup(Phone); Record lookup(const Phone); // redeclares Record lookup(Phone) Record lookup(Phone*); Record lookup(Phone* const); // redeclares Record lookup(Phone*)
In these declarations, the second declaration declares the same function as the first.
On the other hand, we can overload based on whether the parameter is a reference(or pointer) to the const or nonconst version of a given type; such consts are low-level:
// functions taking const and nonconst references or pointers have different parameters // declarations for four independent, overloaded functions Record lookup(Account&); // function that takes a reference to Account Record lookup(const Account&); // new function that takes a const reference Record lookup(Account*); // new function, takes a pointer to Account Record lookup(const Account*); // new function, takes a pointer to const
-
We may define defaults for one ormore parameters. However, if a parameter has a default argument, all the parametersthat follow it must also have default arguments.
-
The default arguments are used for thetrailing (right-most) arguments of a call.
Part of the work of designing a function with default arguments is ordering theparameters so that those least likely to use a default value appear first and thosemost likely to use a default appear last.