In general, the
this pointer doesn't point to an object that is
valid or
fully-formed until the initialization of the object is complete (all the necessary constructors have completed).
Until that point, the lifetime of the object pointed to by
this has not yet begun.
Within the constructor, however, we may take advantage of the fact that some subobjects are already within their lifetime, and use the
this pointer (and
only the
this pointer) to access those subobjects:
you can access any base class subobjects that are within their lifetime;
if a member subobject is already initialized, you can access it.
However, virtual member functions are statically dispatched inside the constructor,
Member functions inside the class may rely on an invariant that isn't yet established,
And you may not access sub-objects that are not initialized.
Could I use m_afterStuff in the callback |
Yes, but you can not invoke the callback until
m_afterStuff is initialized. Note that a lambda capture of
[this] captures the current object
by reference.