#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 + +