草庐IT

collectionProto

全部标签

c++ - 使 shared_ptr 失去内存所有权

我有一个shared_ptr我绕过它。最终,在某些情况下,我想将原始指针传递给一个函数,然后该函数成为内存所有者。在这些情况下shared_ptr不再负责释放内存,因为我调用的函数获得了所有权。我如何获得shared_ptr失去所有权?我想要shared_ptr的原因失去所有权是因为我想使用ProtocolBuffer的AddAllocated功能,它接受一个已经分配的指针并获得它的所有权。例子:shared_ptrmyProtoSharedPtr=//bythispointthisisthelastreferencetotheheapallocatedMyProto//Iwantto