Hello
I have a class someclass with somefunction;
Now I want to create a boost thread with somefunction:
What am I doing wrong?Code:someclass sc; boost::thread thr(&sc.somefunction); thr.join();
Should I use bind instead?
Hello
I have a class someclass with somefunction;
Now I want to create a boost thread with somefunction:
What am I doing wrong?Code:someclass sc; boost::thread thr(&sc.somefunction); thr.join();
Should I use bind instead?
To start with you aren't doing what you think. You aren't passing a reference to the somefunction() member function.
You can't get the address of a member function for reasons having to do with the fact member functions add an extra parameter (the *This parameter) . You can however define a static function and create your member function to call it. It is then possible to get the address of a static function with the following syntax:
&Class::static_function
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
what Mario F. said is true, however you can achieve the effect you're looking for with boost.bind
I love bind. It's just so awesome, I don't think I could program in C++ without it anymore.Code:someclass sc; // assuming somefunction takes no params boost::thread thr(boost::bind(&someclass::somefunction, sc); thr.join();
"I saw a sign that said 'Drink Canada Dry', so I started"
-- Brendan Behan
Free Compiler: Visual C++ 2005 Express
If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?
I'm actually wanting to study boost::bind and the acompanying function object libraries. Only read good things about them. You just shown me another reason
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
it is cool, but you have to be careful. when you find yourself writing code like this
it's probably time to just use a for loopCode:std::for_each (m_elementList.begin(), m_elementList.end(), bind(TiXmlElement::SetAttribute, pNewElement, bind(XMLBaseElement::GetName, _1), bind(XMLBaseElement::GetStringValue, _1))); // equiv to // for each iter in m_elementList // pNewElement->SetAttribute((*iter)->GetName(), (*iter)->GetStringValue());
"I saw a sign that said 'Drink Canada Dry', so I started"
-- Brendan Behan
Free Compiler: Visual C++ 2005 Express
If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?