I have the following code (this is some semi-sudo code, which may not 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 << test
does not yield any output, because m_test
is ""
instead of "Foo bar"
. Why is this? I thought that passing this
as the 2nd argument to bind
would allow me to access the same instance from b()
- am I incorrect?