samedi 6 janvier 2018

C++ passing function in argument to another function

I am trying to pass function to a function, declaration looks like

double fun1(const double* ang, std::function<double(double)> f1)

In the main(), I am creating function pointer and pointing it to another function as

std::function<double(double)> f2 = &fun5; //line1

and calling function fun1 as

double x = fun1(&a,f2);

This works. But, if I call function as

double x = fun1(&a,&f2);

,it gives error as

could not convert '& f2' from 'std::function*' to 'std::function

Creating reference works at line1 but calling function with reference does not work. Any idea why is this happening?

Aucun commentaire:

Enregistrer un commentaire