CC++ 函数指针(指向函数的指针)高级篇

CC++ 函数指针(指向函数的指针)高级篇,第1张

C/C++ 函数指针(指向函数的指针)高级篇

代码

头文件:

//
// Created by hsj on 2022/1/6.
//

#ifndef CLION_CPP_T_POINTER_TO_FUNC_H
#define CLION_CPP_T_POINTER_TO_FUNC_H
//函数指针(指向函数的指针测试)高级篇
void test_pointer_to_func();
//一些函数原型
const double * f1(const double arr[],int n);
const double * f2(const double [],int n);
const double * f3(const double *,int n);
#endif //CLION_CPP_T_POINTER_TO_FUNC_H

cpp文件:

//
// Created by hsj on 2022/1/6.
//
#include 
#include "t_pointer_to_func.h"

//函数指针(指向函数的指针测试)高级篇
void test_pointer_to_func(){

    using namespace std;
    double av[3]{1112.3,1542.6,2227.9};

    //简单的函数指针
    const double * (*p1)(const double arr[],int n) = f1;
    auto p2 = f2;
    cout<<"return addr:"<<(*p1)(av,3)<<"return addr to value:"<<*(*p1)(av,3)< 

输出:

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5698575.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存