码迷,mamicode.com
首页 > 其他好文 > 详细

函数指针的使用

时间:2017-05-25 01:24:20      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:data   地址   void   使用   color   stream   family   out   oid   

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

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

#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; }

 

函数指针的使用

标签:data   地址   void   使用   color   stream   family   out   oid   

原文地址:http://www.cnblogs.com/zuixime0515/p/6901710.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!