It's because you can't make a shared pointer from this
just like that. By doing it you now have two shared pointers to the Trans
instance, both pointing to the same instance but with their separate reference counters. That means that both will try to delete
the pointer.
You need to use std::enable_shared_from_this
. The linked reference page have a very good example of your problem.