我正在尝试像这样创建一个仿函数:
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);
}
};
我正在尝试运行以下代码:
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;
}
但是,我没有得到任何输出。似乎抛出了一些异常,但是 eclipse 并没有向我显示一个,而只是显示该程序已终止。
有任何想法吗?