I've got a nice error when I try to insert my map of method pointer:
nts::IComponent *builder::createComponent(const std::string &type,
const std::string &value) {
fptr ptr = listFunction[type];
return (ptr(value));
}
builder::builder() {
listFunction.insert(make_pair("4081", &builder::create4081));
}
nts::IComponent *builder::create4081(string const &value) const {
return new c4081(value);
}
Here's the definition:
class builder {
typedef IComponent *(*fptr)(string const &);
private:
map<string, fptr const> listFunction;
//composants
IComponent *create4081(string const &) const;
public:
builder();
IComponent *createComponent(const std::string &type, const std::string &value);
};
And here's the error:
home/aherys/Documents/nanotekspicelib/builder.cpp: Dans le constructeur « builder::builder() »:
/home/aherys/Documents/nanotekspicelib/builder.cpp:15:64: erreur : no matching function for call to « std::map<std::__cxx11::basic_string<char>, nts::IComponent* (* const)(const std::__cxx11::basic_string<char>&)>::insert(std::pair<const char*, nts::IComponent* (builder::*)(const std::__cxx11::basic_string<char>&) const>) »
listFunction.insert(make_pair("4081", &builder::create4081));
^
In file included from /usr/include/c++/6.3.1/map:61:0,
from /home/aherys/Documents/nanotekspicelib/builder.h:10,
from /home/aherys/Documents/nanotekspicelib/builder.cpp:5:
/usr/include/c++/6.3.1/bits/stl_map.h:731:7: note : candidate: std::pair<typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<std::pair<const _Key, _Tp> >::other>::iterator, bool> std::map<_Key, _Tp, _Compare, _Alloc>::insert(const value_type&) [with _Key = std::__cxx11::basic_string<char>; _Tp = nts::IComponent* (* const)(const std::__cxx11::basic_string<char>&); _Compare = std::less<std::__cxx11::basic_string<char> >; _Alloc = std::allocator<std::pair<const std::__cxx11::basic_string<char>, nts::IComponent* (* const)(const std::__cxx11::basic_string<char>&)> >; typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<std::pair<const _Key, _Tp> >::other>::iterator = std::_Rb_tree_iterator<std::pair<const std::__cxx11::basic_string<char>, nts::IComponent* (* const)(const std::__cxx11::basic_string<char>&)> >; std::map<_Key, _Tp, _Compare, _Alloc>::value_type = std::pair<const std::__cxx11::basic_string<char>, nts::IComponent* (* const)(const std::__cxx11::basic_string<char>&)>]
insert(const value_type& __x)
Trying a lot of things, but it look like I miss something. I didn't understand where is the syntax or dereference error. Can you explain?