Passing a pntr of a function to a function

Passing a pointer of a function to a function


//============================================================================
// Name        : passFunctToFunct.cpp
// Author      : chd
// Version     :
// Copyright   :
// Description : Passing a pointer of a function to a function,C++ Ansi-style
//============================================================================

#include <iostream>
using namespace std;

typedef double  (*funct) (double);
double integral(funct , double, double);
double square(double);


int main() {

	double a,b,d;
	a=2;
	b=3;
	funct tmpf=square;
	double g=integral(tmpf, a, b);
	cout<<g;
	
}


double integral(funct f,double a, double b){
	return f((a+b)*0.5)*(b-a);
}

double square(double d){
	return d*d;
}