Example program that fails to compile (boost::bind and boost::function called for collection)
Below is a a test program with the purpose of calling member function for each
element of the collection. Argument of this member function is a
boost::function.
I put compilation error after the source code.
Any help will be greatly appreciated.
#include
AMDG Archie14 wrote:
delegate dosomething; Test(CLIENTS& val) : m_clients(val) {} void run() { std::for_each(m_clients().begin(), m_clients().end(), boost::bind(&CLIENTS::CLIENT::commandhandler, boost::ref(dosomething), _1 )); } };
The parameters to boost::bind are in the wrong order. Try: boost::bind(&CLIENTS::CLIENT::commandhandler, _1, boost::ref(dosomething))); In Christ, Steven Watanabe
Steven Watanabe
AMDG
Archie14 wrote:
delegate dosomething; Test(CLIENTS& val) : m_clients(val) {} void run() { std::for_each(m_clients().begin(), m_clients().end(), boost::bind(&CLIENTS::CLIENT::commandhandler, boost::ref(dosomething), _1 )); } };
The parameters to boost::bind are in the wrong order.
Try:
boost::bind(&CLIENTS::CLIENT::commandhandler, _1, boost::ref(dosomething)));
In Christ, Steven Watanabe
Steven,
Thank you very much for the help. I have a follow-up question regarding
boost::bind. Specifically - how can I bind one boost::function to another? Here
is the short example that fails to compile:
#include
AMDG Archie14 wrote:
typedef boost::function
delegateOne; typedef boost::function delegateTwo; class A : public boost::noncopyable { public: void commandhandler(delegateOne& f) { // I want to replace first argument in "delegateOne" with value 100. delegateTwo two = boost::bind(&f, 100, _2, _3); } };
I assume that you want to store a reference to f in two? use boost::ref(f) instead of &f. In Christ, Steven Watanabe
participants (2)
-
Archie14
-
Steven Watanabe