mercredi 4 février 2015

C++ returning a function from within namespace using std::function

I'm trying to return a function using std::function but having typing problems... see code:



#include "LossFunction.hpp"


LossFunction::LossFunction() {
}

LossFunction::LossFunction(int functionType) {
this->functionType = functionType;
this->fun = this->getLossFunction();
}
LossFunction::~LossFunction() {

}

std::function<float(Input,Output)> LossFunction::getLossFunction() {
switch (this->functionType){
case 0:
return this->f1;
break;
default:
return this->f1;
break;
}
}


I'm getting the following error at compile time:



LossFunction.cpp: In member function ‘std::function<float(Input, Output)> LossFunction::getLossFunction()’:
LossFunction.cpp:18:17: error: cannot convert ‘LossFunction::f1’ from type ‘float (LossFunction::)(Input, Output)’ to type ‘std::function<float(Input, Output)>’
return this->f1;
^


LossFunction.cpp:21:17: error: cannot convert ‘LossFunction::f1’ from type ‘float (LossFunction::)(Input, Output)’ to type ‘std::function’ return this->f1;


Any guidance on this issue would be appreciated...


Thanks in advance


Aucun commentaire:

Enregistrer un commentaire