Are there any issues when passing 'this' to another object in the initializer list in the following code?
class Callback { public: virtual void DoCallback() = 0; };
class B
{
Callback& cb;
public:
B(Callback& callback) : cb(callback) {}
void StartThread();
static void Thread()
{
while (!Shutdown())
{
WaitForSomething();
cb.DoCallback();
}
}
};
class A : public Callback
{
B b;
public:
A() : b(*this) {b.StartThread();}
void DoCallback() {}
};
If it is unsafe to do that, what's the best alternative?