我有将 std::shared_ptr 作为参数的函数,所以我被迫使用 std::shared_ptr,但我传递给函数的对象不是动态分配的。如何将对象包装在 std::shared_ptr 中并让 std::shared_ptr 不对它调用 delete。
最佳答案
MyType t;
nasty_function(std::shared_ptr<MyType>(&t, [](MyType*){}));
关于c++ - 你如何让 std::shared_ptr 不调用 delete(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20131877/