I have the following code:
struct STFRandomTreeFunction
{
typedef double (*function_ptr)(const STFDataPoint& data, boost::unordered_map& 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, std::string function_id)
:image_cache(&cache), function(function), function_id(function_id){}
std::string get_function_id(){
return function_id;
}
double operator()(const TrainingDataPoint& data_point){
return function(data_point, *image_cache);
}
};
unordered_map<string, STFRandomTreeFunctor> lut;
double a(const STFDataPoint& b, unordered_map<string, Mat>& c){
return 5;
}
int main(int argc, char* argv[]) {
unordered_map<string, Mat> cache;
lut["a"] = STFRandomTreeFunctor(cache, a, "a");
}
when I try to build I get the following error: boost/unordered/detail/allocate.hpp:262:1: error: no matching function for call to ‘STFRandomTreeFunctor::STFRandomTreeFunctor()’
But I have no idea why boost is trying to call STFRandomTreeFunctor(), is this because when we create the empty map, it tries to create a STFRandomTreeFunctor? If so, how can I work around this?
Thanks
The call
will first create an empty entry in
themap(cfr. operator[]: “Effects:If the container does not already contain an elements with a key equivalent to k, inserts the value
std::pair<key_type const, mapped_type>(k, mapped_type())“). To constructmapped_type()it needs a default constructor.If you want to avoid that, use the
insertfunction:But this way, you’ll need a copy constructor (or a move-constructor), since the newly created
pairwill be copied into the map.