使用 typedef 简化函数指针
2015-04-24 23:55
239 查看
#include <stdio.h> #include <stdlib.h> #include <Windows.h> /* typedef 可以给函数指针类型取一个别名 typedef 没有定义新的类型、仅仅是给已经有的类型取一个别名、减少我们的坑爹输入 */ int add(int a, int b){ return a + b; } //函数指针的定义方法:int (*pAdd)(int a, int b) 挖空函数名换成(*xxx) //函数指针的类型:int (*)(int a, int b) void msg(char * str){ MessageBoxA(0, str, str, 0); } void main1(){ int(*pAdd)(int a, int b);//定义函数指针 pAdd = add; // 初始化 printf("\n %d ", pAdd(3, 3));// 调用 void(*pMsg)(char * str) = msg; // 定义并且初始化 pMsg("nihao zhongguo "); getchar(); } typedef int (*pAdd)(int a, int b); typedef void (*pMsg)(char * str); void main(){ pAdd add1 = add; printf("\n %d ", add1(3, 3)); pMsg msg1 = msg; msg1("你好 天朝!"); getchar(); }
相关文章推荐
- 使用typedef简化函数指针的声明
- 第十七章 特殊成员_使用typedef简化函数指针的声明
- 使用typedef简化函数指针的声明及定义
- 关于C++中函数指针的使用(包含对typedef用法的讨论)
- 关于C++中函数指针的使用(包含对typedef用法的讨论)
- typedef使用大全3(指向函数的指针)//typedef的使用可以隐藏复杂的函数指针语法
- 关于C++中函数指针的使用(包含对typedef用法的讨论)
- typedef使用大全3(指向函数的指针)
- 关于C++中函数指针的使用(包含对typedef用法的讨论)
- 关于C++中函数指针的使用(包含对typedef用法的讨论)
- typedef使用大全3(指向函数的指针)
- 关于C++中函数指针的使用(包含对typedef用法的讨论)
- 关于C++中函数指针的使用(包含对typedef用法的讨论)
- 关于C++中函数指针的使用(包含对typedef用法的讨论)
- 关于C++中函数指针的使用(包含对typedef用法的讨论)
- 关于C++中函数指针的使用(包含对typedef用法的讨论)
- (转)关于C++中函数指针的使用(包含对typedef用法的讨论)
- 关于C++中函数指针的使用(包含对typedef用法的讨论)
- typedef使用(指向函数的指针)
- 关于C++中函数指针的使用(包含对typedef用法的讨论)