Looping over the parameters of a defined function in C++ -


i rather beginner in c++ , don't know how solve following issue. have working code find root of function using brent method. issue interested in how loop on different values of parameters of function, assuming same specification.

here simpler example. call function call defined function afunction.

#include <stdio.h> #include <math.h> double   x1,x2,res,r;   // simple function double afunction(double x) {   return ((x)+2); }   // second function call first 1   double addf( double x1, double x2, double *res )   {  double result=afunction(x1)+afunction(x2);       return (result);    }  int main()  {   x1=1.0;   x2=2.0;   r=afunction(x1,x2,&res);  } 

what interested in loop on parameter(s) of defined function, considering fact have afunction depending on x. is, consider function defined below:

// simple function double afunction(double x) {   return ((x)+a); } 

i want repeatedly call afunction different values of can stored in vector.

if mean looping on parameters , calling function, have pass parameters in come container, or use variable length list.

double addf( std::list<double> const& params) const {    double result = 0;    for( auto& d : params) result += afunction( d);         return result;    } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -