C++ std::shared_ptr的使用

普通指针与share_ptr的互相转换:

struct test
{
	int num;
	string name;
};

test* pTest = new test();
std::shared_ptr<test> ptr_test = std::shared_ptr<test>(pTest); //普通指针转shared_ptr
	
std::shared_ptr<test> ptr_test2 = std::make_shared<test>();
test* pTest2 = ptr_test2.get(); //shared_ptr转普通指针

  

原文链接: https://www.cnblogs.com/stonemjl/p/12580015.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    C++ std::shared_ptr的使用

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/194930

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月12日 下午6:50
下一篇 2023年2月12日 下午6:50

相关推荐