c++ - Can't store boost::bind functions in std::map -
this question exact duplicate of:
i trying map functions using std::bind , std::map
#include <boost/bind/bind.hpp> #include <boost/function/function0.hpp> #include <map> class foo { public: foo(); void bar(bool i) {cout << << endl;} private: typedef boost::function<void(bool)> function; std::map<int, function> functionmap; } foo::foo() { functionmap[0] = boost::bind(&foo::bar, this, _1); }
the error getting following:
error c2582: 'operator =' function unavailable in 'boost::function< signature>'
what problem be?
you need include <boost/function.hpp>
, compiles:
#include <iostream> #include <boost/bind/bind.hpp> #include <boost/function.hpp> #include <map> class foo { public: foo(); void bar(bool i) {std::cout << << std::endl;} private: typedef boost::function<void(bool)> function; std::map<int, function> functionmap; }; foo::foo() { functionmap[0] = boost::bind(&foo::bar, this, _1); }
Comments
Post a Comment