函数指针的使用

函数指针是指向函数的指针变量。 因而“函数指针”本身首先应是指针变量,只不过该指针变量指向函数;

为了方便自己的理解,附上下面一段断码:

#include <cstdio>
#include <iostream>

using namespace std;

typedef struct Data{
    int age;
    char sex;
}PersonData;

PersonData  Init(int a,char c){
    PersonData  i;
    i.age = a;
    i.sex = c;
return i; } void main(){ PersonData (*TestFunc)(int,char); PersonData Demo; TestFunc = Init; //将Init函数地址赋给TestFunc Demo = TestFunc(20,'M'); cout << Demo.age << " " << Demo.sex << endl; }

 

posted @ 2017-05-25 00:21  醉曦  阅读(176)  评论(0编辑  收藏  举报