When reviewing old code I encountered the following construction:
class Base
{
public:
Base(Child* aChild = 0){}
}
class Child: public Base
{
public:
Child():Base(this){}
}
Beside the fact that it looks awful, I wonder if it is safe to provide the 'this' pointer to the parent class in the initializer list? I found a few examples where the 'this' pointer from the parent is provided to a child class pointer member for example in this question by bavaza. Since the parent class is kind of an implicit member of the child class, I suppose that the above construction is safe, as long as the Base class is not using the this pointer inside its constructor. Nevertheless, I want to confirm that this is always the case and not undefined behavior.
I'm surprised that I did not find an answer to this basic question. Probably I used the wrong key words. So please excuse me if it turns out to be a duplicate nevertheless.