为结构体中函数指针赋值的两种方法
2018-01-31 10:53
253 查看
/** 02. * 为结构体中的指针数组赋值 03. */ 04. 05.#include <stdio.h> 06. 07.typedef struct test 08.{ 09. void (*p)(void); 10. void (*q)(void); 11. void (*y)(void); 12.}test; 13. 14.void f1(void) 15.{ 16. printf("f1\n"); 17.} 18. 19.void f2(void) 20.{ 21. printf("f2\n"); 22.} 23. 24.void f3(void) 25.{ 26. printf("f3\n"); 27.} 28. 29.int main(void) 30.{ 31. test aa = { 32. p : f1, //方法1 33. .q = f2, //方法2, 一般这种方式在全局变量初始化的时候常用 34. }; 35. aa.y = f3; //方法3 36. 37. aa.p(); 38. aa.q(); 39. aa.y(); 40. 41. return 0; 42.}
相关文章推荐
- 为结构体中函数指针赋值的两种方法
- 为结构体中函数指针赋值的两种方法
- 为结构体中函数指针赋值的两种方法
- 为结构体中函数指针赋值的两种方法
- 为结构体中函数指针赋值的两种方法
- 为结构体中函数指针赋值的两种方法
- 为结构体中函数指针赋值的两种方法
- 为结构体中函数指针赋值的两种方法
- 为结构体中函数指针赋值的两种方法
- 为结构体中函数指针赋值的两种方法
- 为结构体中函数指针赋值的两种方法
- 为结构体中函数指针赋值的两种方法
- 为结构体中函数指针赋值的两种方法
- 为结构体中函数指针赋值的两种方法
- 为结构体中函数指针赋值的两种方法
- 为结构体中函数指针赋值的两种方法
- 函数指针在结构体中的赋值方法
- java使用反射给对象属性赋值的两种方法
- Delphi函数指针的两种定义(对象方法存在一个隐藏参数self,所以不能相互赋值)
- 【OC学习-8】存取器方法?getter和setter?其实就是赋值和返回值的两种函数