I have the following code (this is a half-court code that cannot compile):
class FooBar {
public:
void a();
void b();
boost::shared_ptr<boost::thread> m_thread;
std::string m_test;
};
void FooBar::a() {
m_test = "Foo bar"
m_thread = shared_ptr<thread>(new thread(bind(&FooBar::b, this)));
}
void FooBar::b() {
cout << m_test;
}
The code cout << testgives no output, because there m_testis ""instead "Foo bar". Why is this? I thought passing thisas the second argument to bindwould allow me to access the same instance from b()- am I wrong?
source
share