相互转化见示例

 1 struct test
 2 {
 3      int num;
 4      string name;
 5 };
 6 
 7 test* pTest = new test();
 8 std::shared_ptr<test> ptr_test = std::shared_ptr<test>(pTest); //普通指针转shared_ptr
 9 
10 std::shared_ptr<test> ptr_test2 = std::make_shared<test>();
11 test* pTest2 = ptr_test2.get(); //shared_ptr转普通指针

 

相关文章:

  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案