help with boost function in std map
Hello
Why will the following code produce error:
Quote:
error C2664: 'std::_Tree<_Traits>::iterator std::_Tree<_Traits>::insert(std::_Tree<_Traits>::i terator,const std::pair<_Ty1,_Ty2> &)' : cannot convert parameter 1 from 'std::string' to 'std::_Tree<_Traits>::iterator'
1> with
1> [
1> _Traits=std::_Tmap_traits<std::string,user_input:: command_handler,std::less<std::string>,std::alloca tor<std::pair<const std::string,user_input::command_handler>>,false>,
1> _Ty1=const std::string,
1> _Ty2=user_input::command_handler
1> ]
1> and
1> [
1> _Traits=std::_Tmap_traits<std::string,user_input:: command_handler,std::less<std::string>,std::alloca tor<std::pair<const std::string,user_input::command_handler>>,false>
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Code:
class user_input {
public:
user_input() {
}
class command_handler {
public:
command_handler() { }
command_handler(
boost::program_options::options_description desc,
boost::function<void (boost::program_options::variables_map vars)> f) :
m_desc(desc), m_func(f) {
}
private:
boost::program_options::options_description m_desc;
boost::function<void (variables_map vars)> m_func;
};
void add_function(std::string name, boost::program_options::options_description desc,
boost::function<void (boost::program_options::variables_map vars)> func)
{
m_handlers.insert(name, command_handler(desc, func) );
}
private:
std::map<std::string, command_handler> m_handlers;
};
Many thanks for help!