You most likely want:
void registerCallback(std::tr1::function<void (std::string)> cb) { this->callbacks.push_back(cb); }
with callbacks container (depending on what you like) of std::tr1::function objects instead of one. When sending, repeat callbacks.
Also, if you want to remove callbacks later, you can do something in this direction:
// I use list because I don't want the iterators to be invalid // after I add / remove elements std::list<std::function<void(std::string)>> callbacks; ... typedef std::list<std::function<void(std::string)>>::iterator callback_id; callback_id register_callback(std::function<void(std::string)> f) { return callbacks.insert(callbacks.end(), f); } void unregister_callback(callback_id id) { callbacks.erase(id); }
Alexandre C.
source share