C ++ function pointer for simple use

Source: Internet
Author: User

Function pointer:

The function pointer must contain the memory address of the function to be called. to work properly, the pointer must also contain other information, that is, the parameter type and return type in the parameter list of the function to which the Pointer Points. Therefore, when declaring a function pointer, you must specify the parameter type, return type, and pointer name of the function that the pointer can point.

The function pointer is generally in the following format:

Return type (* pointer) (parameter type list );

Note: The parentheses on the pointer name are indispensable. Otherwise, * will be combined with the return type to form a function prototype.

Example:
# Include

 
  
Using std: cout; using std: endl; // function declaration long sum (long a, long B); long product (long a, long B ); int main (int argc, char * argv []) {// function pointer declaration long (* pfun) (long, long) = 0; // point to the product function pfun = product; cout <

  

   


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.