函数指针
作者:互联网
#include <iostream> using namespace std; int jh(const void* a, const void* b) { int i = *((int*)a);//类型转换 int j = *((int*)b); cout << "jh被调用" << endl; return i - j; } int main(void) { int k = 10, b = 20; int a[5] = { 7,2,5,3,6 }; int(*fp)(const void*, const void*);//创建函数指针 fp = &jh; //fp(&A, &b);调用 (*fp)(&k, &b); qsort(a, sizeof(a) / sizeof(int), sizeof(int), &jh);//排序 for (int i = 0; i < 5; i++) { cout << a[i] << endl; } return 0; }
标签:std,类型转换,const,cout,int,void,函数指针 来源: https://www.cnblogs.com/WU20/p/16437648.html