gpt4 book ai didi

c++ - 你如何让 std::shared_ptr 不调用 delete()

转载 作者:IT老高 更新时间:2023-10-28 12:55:19 26 4
gpt4 key购买 nike

我有将 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com