The enable_shared_from_this
helper contains a weak pointer that is set when creating shared pointer to the object. That means there is the reference-count (allocated separately or together with the object using make_shared
) and an extra weak_ptr
in the object.
Now why doesn't it simply contain the reference count instead? When setting shared_ptr
from dumb pointer, the type has to be fully defined, so the shared_ptr
constructor or assignment operator can detect the type is derived from enable_shared_from_this
and use the correct counter and the format can remain the same, so copying does not care. In fact, the shared_ptr
already has to detect it to set the embedded weak_ptr
.