I am trying to create a functor like so:
struct STFRandomTreeFunction
{
typedef double (*function_ptr)(const TrainingDataPoint& data, boost::unordered_map<std::string, cv::Mat>& preloaded_images);
};
struct STFRandomTreeFunctor
{
private:
boost::unordered_map<std::string, cv::Mat> *image_cache;
STFRandomTreeFunction::function_ptr function;
std::string function_id;
public:
STFRandomTreeFunctor(boost::unordered_map<std::string, cv::Mat>& cache, STFRandomTreeFunction::function_ptr function_ptr, std::string function_id){
image_cache = &cache;
this->function = function;
this->function_id = function_id;
}
std::string get_function_id(){
return function_id;
}
double operator()(const TrainingDataPoint& data_point){
return function(data_point, *image_cache);
}
};
And am trying to run the following code:
double something(const TrainingDataPoint& a, unordered_map<string, Mat>& cache){
return 5;
}
int main(int argc, char* argv[]) {
unordered_map<string, Mat> cache;
STFRandomTreeFunctor functor = STFRandomTreeFunctor(cache, something, "id");
TrainingDataPoint d = TrainingDataPoint(1,2,"", ImagePoint(1,2), ImagePoint(1,2), "");
double value = functor(d);
cout << "Value is " << value << endl;
}
However, I get no output. It appears as though some exception is throwing however eclipse is not showing me one but just showing that the program has terminated.
Any ideas?
In the constructor of
STFRandomTreeFunctorThat’s self assignment. I assume you meant to do this: