The difference between C + + function pointer and pointer function __jquery

Source: Internet
Author: User
(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.;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.