2016-07-25 57 views
0

我嘗試使用std ::綁定和std ::地圖不能存儲的boost ::綁定功能的std ::地圖

#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 ::功能<簽名>'

不可用可能的問題是什麼?

+0

工作完全正常http://ideone.com/ofViT8 – imreal

回答

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); 
} 

live example