c++ 函数指针应用,定义一个方法,传入两个参数和一个函数指针,并返回结果
#include <iostream> #include <string> using namespace std; double add(double x, double y); double calculate(double a, double b, double (*pf)(double, double)); int main() { double q = calculate(2.5, 10.4, add); cout << q << endl; return 0; } double add(double x, double y) { return x + y; } double calculate(double a, double b, double (*pf)(double, double)) { return (*pf)(a, b); }