"C + +" function pointer macro definition

Source: Internet
Author: User

The first sentence of the example was startled by the case of Uncle Mouse's study of the virtual function table (http://blog.csdn.net/haoel/article/details/1948051).

void (*fun) (void);

Thanks to the RR help, understand.

This line of code defines a function pointer type fun, function pointer, which refers to a pointer to a function

The first void refers to the function return value type, the second void is the list of function parameter types, and the general syntax:

typedef returntype (*name) (Parameter1type,parameter1type,...)

Examples are as follows:

typedefstring(*FUN1) (void); typedefvoid(*FUN2) (string,int);stringGetData () {strings; CIN>>s; returns;}voidPutData (stringSintAge ) {cout<<"My name is"<< s <<", my age is"<< Age <<Endl;}int_tmain (intARGC, _tchar*argv[]) {Fun1Get= GetData;//get is a pointer to GetData (), and the function name is the address    strings =Get(); cout<< s <<Endl; Fun2 put=PutData; Put ("Lizy", -); System ("Pause"); return 0;}

Results:

"C + +" function pointer macro definition

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.