Use of callback functions and function pointers in C + +

Source: Internet
Author: User
#include "stdafx.h" #include <iostream>//#include <string>using namespace std;typedef struct {char * from; char * To;char * Id;char * type;} head;typedef struct {head *head_;char * MSG_;} Msg;struct sn {char * NE;}; typedef void (*callback) (void *PARAM_);//create a function that needs to use the callback function void functions (CALLBACK func, void *param) {func (param);} Create a function that is consistent with the function pointer type void Func_hello (void *param) {char * d= (char*) param;cout << d << Endl;} int main () {string i = "W3r4werwe"; char *ff = (char*) i.c_str ();//Use function functions that require a callback function (Func_hello, (void*) i.c_str ());// Declare the function pointer callback myfun;//assign the function address to the function pointer myfun = func_hello;//Use the function pointer to call the function Myfun ((void*) i.c_str ()); System ("pause");    return 0;}

  

Use of callback functions and function pointers in C + +

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.