我正在尝试使用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 << i << endl;}
private:
typedef boost::function<void(bool)> Function;
std::map<int, Function> functionMap;
}
Foo::Foo() {
functionMap[0] = boost::bind(&Foo::bar, this, _1);
}
我得到的错误如下:
错误C2582:'boost :: function&lt;'中的'operator ='函数不可用签名&GT;'
问题是什么?
答案 0 :(得分:0)
你需要包含<boost/function.hpp>
,然后编译:
#include <iostream>
#include <boost/bind/bind.hpp>
#include <boost/function.hpp>
#include <map>
class Foo {
public:
Foo();
void bar(bool i) {std::cout << i << std::endl;}
private:
typedef boost::function<void(bool)> Function;
std::map<int, Function> functionMap;
};
Foo::Foo() {
functionMap[0] = boost::bind(&Foo::bar, this, _1);
}