Initialize a reference – warning C4355: ‘this’ : used in base member initializer list

Note this is a warning (so it is dangerous not illegal).

What the compiler is worried about is that you are passing a pointer for an object that has not been fully initialized. Thus if the pointer is used in the B class constructor you are in undefined behavior.

So if you do use this the only thing you can do is assign the pointer to a member variable (reference or pointer). But note be careful of the assignment to a variable as you may invoke an implicit cast (I am not sure if that is actually a problem but the RTTI is not available until the object is fully formed).

What are you trying to achieve by storing the reference?

Leave a Comment