The code below gives me a compile-time error. Anyone have any ideas on how to fix this or what might be causing it?
‘boost::operator ==’ : 4 overloads have similar conversions
typedef boost::function<void (boost::weak_ptr<std::string>)> Callback;
std::list<Callback> callbacks;
Callback func;
callbacks.remove(func); // This causes the error
When you call
std::list<T>::remove, it looks for the value to remove by comparing it to the elements in the list. In the case ofboost::functionobjects, this fails becauseboost::functionobjects can’t be compared. See Why can’t I compare boost::function objects with operator== or operator!= in the Boost Function FAQ.You’ll need to remove the objects from the list in another way (e.g. with
eraseand an iterator).In this case, it looks like you’re implementing something similar to the Boost.Signals library. You may want to use that instead – it provides a way to register multiple callbacks and remove them.