zoukankan      html  css  js  c++  java
  • 函数指针

    t函数指针声明如下:

    double (*pf) (int);                 //pt points to a function that takes one int argument and that returns type double

    提示:通常,要声明指向特定类型的函数的指针,可以首先编写这种函数的原型,然后用(*pf)替换函数名。这样Pf就是这类函数的指针。

    eg:

    double pam(int);

    double (*pf)(int);

    pf=pam;

    程序示例:

    #include<iostream>
    using namespace std;
    double betsy(int);
    double pam(int);
    //second argument is pointer to a type double function that
    //takes a type int argument
    void estimate(int lines,double(*pf)(int));
    int main()
    {
        int code;
        cout<<"How many lines of code do you need?";
        cin>>code;
        cout<<"Here are betsy's estimate: ";
        estimate(code,betsy);
        cout<<"Here are pam's estimate: ";
        estimate(code,pam);
        return 0;
    }
    double betsy(int lns)
    {
        return 0.05*lns;
    }
    double pam(int lns)
    {
        return 0.03*lns+0.0004*lns*lns;
    }
    void estimate(int lines,double(*pf)(int))
    {
        cout<<lines<<"lines will take";
        cout<<(*pf)(lines)<<"hour(s) ";
    }

  • 相关阅读:
    Centos7安装redis
    Cookie和Session的区别
    JavaWeb中的域对象
    ServletContext使用介绍
    Java Web核心组件之Servlet的使用介绍
    关于反射的杂谈
    leetcode117search-in-rotated-sorted-array
    23longest-consecutive-sequence
    leetcode24:word-ladder-ii
    leetcode25word-ladder
  • 原文地址:https://www.cnblogs.com/guangliang/p/4355338.html
Copyright © 2011-2022 走看看