You have two shared_ptr trying to own the same pointer (and they do not know about each other). This causes both of them to try to free the same address.
a trying to completely own this . But then you pass this to CreateProxy() , which creates a new shared_ptr that tries to completely own this . The new shared_ptr does not know about a , so not one of them shares its reference count. shared_ptr needs to split the reference count, not just the pointer itself.
If you want to split the pointer between two shared_ptr s, they must know about each other (so that they can update the reference count). When Girl calls CreateProxy() , he needs to pass shared_ptr to this .
Perhaps this would be a good time to use std::enable_shared_from_this() .
source share