#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_); //創建需要使用回調函數的函數 void function(CALLBACK func, void *param) { func(param); } //創建和函數指針類型一致的函數 void func_hello(void *param) { char * d= (char*)param; cout << d << endl; } int main() { string i = "w3r4werwe"; char *ff = (char*)i.c_str(); //使用需要回調函數的函數 function(func_hello, (void*)i.c_str()); //申明函數指針 CALLBACK myfun; //將函數地址賦值給函數指針 myfun = func_hello; //使用函數指針調用函數 myfun((void*)i.c_str()); system("pause"); return 0; }