I'm developping a class for manage some callbacks such mouse click or display (callback called when window need to be refreshed)
callbacks and handles are saved in maps. I'm trying to create a function that can register a callback in the maps (addCallback).
class CallBackManager {
public:
enum CallBackType {
DISPLAY = 1 << 0,
MOUSE = 1 << 1
};
template<typename T>
void AddCallback(CallBackType type, int hwnd, T f) {
if (type & DISPLAY) {
addDisplayCallback(hwnd, f); // 50 lines of error here
}
if (type & MOUSE) {
addMouseCallback(hwnd, f); // The same here
}
}
private:
void addDisplayCallback(int hwnd, boost::function<void ()> f) {
_display_callback[hwnd] = f;
};
void addMouseCallback(int hwnd, boost::function<void (int, int)> f) {
_mouse_callback[hwnd] = f;
};
std::map<int, boost::function<void ()>> _display_callback;
std::map<int, boost::function<void (int, int)>> _mouse_callback;
};
I call those functions like that :
CallBackManager cbm;
cbm.AddCallBack(
CallBackManager::CallBackType::DISPLAY,
my_handle,
boost::bind(&Foo::Display, this)); // boost::function<void ()>
cbm.AddCallback(
CallBackManager::CallBackType::DISPLAY,
my_handle,
boost::bind(&Foo::Mouse, this, _1, _2)): //boost::function<void (int, int)>
And finally the error is :
error C2784: 'T &boost::_bi::list0::operator [](const boost::reference_wrapper<T> &) const' : could not deduce template argument C:\local\boost_1_57_0_b1\boost\bind\bind.hpp 392
I don't understand this error
(here is the code with the compilation error) https://ideone.com/BdW1Ln