zoukankan      html  css  js  c++  java
  • typedef复杂声明

    在看AMCL源码时,发现typedef的用法看不懂,搜了下,发现是函数指针的重命名

    // Function prototype for the initialization model; generates a sample pose from
    // an appropriate distribution.
    typedef pf_vector_t (*pf_init_model_fn_t) (void *init_data); // Function prototype for the action model; generates a sample pose from
    // an appropriate distribution
    typedef void (*pf_action_model_fn_t) (void *action_data, 
                                          struct _pf_sample_set_t* set);
    
    // Function prototype for the sensor model; determines the probability
    // for the given set of sample poses.
    typedef double (*pf_sensor_model_fn_t) (void *sensor_data, 
                                            struct _pf_sample_set_t* set);

    先看第一个,pf_init_model_fn_t是声明的新名字,也可以这么写

    typedef pf_vector_t (*) (void *init_data) pf_init_model_fn_t;

    这样看就清晰了。

    pf_init_model_fn_t是函数指针,(*)后面是的括号是函数的形参,void *表示无类型指针,可以指向任意类型的变量; (*)前面pf_vector_t值得是这个函数的返回类型。
     
     
    第二个也是这样理解
    typedef void (*) (void *action_data, struct _pf_sample_set_t* set) pf_action_model_fn_t;

    pf_action_model_fn_t是函数指针,指向带两个参数的函数,函数无返回类型。

    第三个同样的理解

    还有其他的复杂声明的,可以看https://www.cnblogs.com/wen-ge/articles/5807509.html

    2021.8.12更新

    上面是函数指针的表示形式,接下来需要知道,为什么要用函数指针,用途有哪些?

    1、回调函数:函数指针作为某个函数的参数。

    2、结构体里面定义函数指针:实现多态过程

  • 相关阅读:
    安装完MySQL数据库设置密码
    pom.xml
    性能测试更像一次科学实验
    gitlab git
    postman
    python3 session cookie
    自动化测试的概念及工具
    项目启动加载配置,以及IP黑名单,使用CommandLineRunner和ApplicationRunner来实现(一般用在网关进行拦截黑名单)
    使用JWT登录生成token
    国际化的实现i18n--错误码国际化以及在springboot项目中使用
  • 原文地址:https://www.cnblogs.com/havain/p/15009833.html
Copyright © 2011-2022 走看看