mardi 29 août 2017

convertion error in a method that return a lambda expression

this code works without problem

#include "iostream"
#include  "functional"
std::function<double (double)> retFun(double* a) {
     return [a](double x) { return x+*a; };
 }

 int main(){

 double*e = new double(3);
 std::cout << retFun(e)(3) << std::endl;}

but if i declare retFun in a object :

.h

class InternalVariables : public Page { private: std::function<double ()> retFun(double* a); }; .cpp

std::function<double ()> InternalVariables::retFun(double *a) { return [a](double b){ return b+ *a;}; }

i obtain the following error

error: could not convert ‘InternalVariables::retFun(double*)::__lambda44{a}’ from ‘InternalVariables::retFun(double*)::__lambda44’ to ‘std::function’ return [a](double b){ return b+ *a;};

Aucun commentaire:

Enregistrer un commentaire