(1) function pointer and pointer function
(1) function pointers
A special pointer that points to the entry of a function;
* * Defines a function pointer p, which can only point to the return value of int, the function of two
int
(*p)/int (int,int);
*
* Maximum value
* The return value is type int, returning the larger one of two integers
/int max (int a, int b) {return
a > b a:b;
}
*
* Find the minimum value
* The return value is type int, returning the smaller one of two
integers
/int min (int a, int b) {return
a < b a:b;
}
int main () {
f = max;//function pointer F point to max
int c = (*f) (1, 2);
f = min; function pointer f points to the minimum value min
c = (*f) (1, 2);
}
(2) pointer function
Returns the function of the pointer, a function whose return value is a pointer;
This is a parameter of two int type, and the return value is the function
int *p (int,int) of the int pointer;
* *
The definition of the pointer function
* The return value is the pointer type int * *
/int *f (int a, int b) {
int *p = (int *) malloc (sizeof (int));
memset (p, 0, sizeof (int));
*p = a + b;
return p;
}
int main () {
int *p1 = NULL;
P1 = f (1, 2);
}
(2) pointer array and array pointer
(1) array of pointers
An array that contains the elements that are pointers
(2) array pointers
A pointer that points to an array
(3) function template and template function
(1) function template
Represents a template that is used specifically to generate functions;
Template <typename t>
void Fun (T a)
{
}
(2) template function
is a function that represents a function generated from a template;
such as: Fun <int>, fun <double>, fun <Shape*> etc; (4) class template and template class
(1) class template
Represents a template that is dedicated to the Production class template;
Template <typename t>
class Vector
{
(2) template class
is a class that represents a class that is generated from a template;
such as:vector<int>, vector<double>, vector<shape*>, etc.;