// ------------------------------------------- // ff.cpp A wrapper for an fptype1 pointer // ------------------------------------------- // See also funtest.cpp #include "w.h" // ---------------------------------------------- class ff : public fun // translator fptype1 -> fun { public: ff(fptype1 fpp); double f(double x); private: fptype1 fp; // copy of pointer wrapped by class ff }; inline ff::ff(fptype1 fpp): fp(fpp) {} inline double ff::f(double x) { return(fp(x)); } // --------------------------------------------------- // Top level test function (its name is an fptype1) double g(double x) { return x*cosh(x); } // --------------------------------------------------- void main() { nl(0); banner("ff.cpp"); //tabulate the top level function g ftab(g,"g",-5,5,7); // create a wrapped `fun' version of g ff *gu = new ff(g); // tabulate gu ftab(gu,"gu",-5,5,7); delete gu; // recover the memory } /* output ----------------------------------------------------- -------- ff.cpp -------- g( -5.000000) = -371.049743 g( -3.571429) = -63.563363 g( -2.142857) = -9.258295 g( -0.714286) = -0.904382 g( 0.714286) = 0.904382 g( 2.142857) = 9.258295 g( 3.571429) = 63.563363 g( 5.000000) = 371.049743 gu( -5.000000) = -371.049743 gu( -3.571429) = -63.563363 gu( -2.142857) = -9.258295 gu( -0.714286) = -0.904382 gu( 0.714286) = 0.904382 gu( 2.142857) = 9.258295 gu( 3.571429) = 63.563363 gu( 5.000000) = 371.049743 */