13.函数指针

// 00222.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>

using namespace std;
typedef void (*CallbackFun)(double height, void* contex);//定义一种新的函数指针

void onHeight(double height, void* contex)
{
printf("current height is %lf", height);
}

void registHeightCallback(CallbackFun callback, void* contex)
{
double h = 100;
callback(h, nullptr);
}


int main()
{

registHeightCallback(onHeight,nullptr);//调用registHeightCallback,CallbackFun callbac是参数指向typedef定义,然后传参
return 0;
}

posted @ 2020-06-27 19:49  janeyjhon1  阅读(54)  评论(0编辑  收藏  举报