No, there's no way to avoid the copy.
This is because there's no inheritance relationship between std::shared_ptr<a>
and std::shared_ptr<b>
, so you can't arbitrarily convert between them.
If you want to take ownership (by moving) of a pointer being passed to a constructor, why not use unique_ptr
instead? IF you aren't taking ownership don't pass it as a smart pointer at all.