您当前的位置: 首页 >  ar

mutourend

暂无认证

  • 4浏览

    0关注

    661博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C++ std::shared_ptr共享指针示例

mutourend 发布时间:2019-03-04 15:54:57 ,浏览量:4

std::shared_ptr 顾名思义,允许有多个owner对同一指针享有所有权,可通过reset或赋值操作变更所有权。

Objects of shared_ptr types have the ability of taking ownership of a pointer and share that ownership: once they take ownership, the group of owners of a pointer become responsible for its deletion when the last one of them releases that ownership.

shared_ptr使用示例:

// shared_ptr::reset example
#include 
#include 

int main () {
   std::shared_ptr sp;  // empty

   sp.reset (new int);       // takes ownership of pointer
   *sp=10;
   std::cout             
关注
打赏
1664532908
查看更多评论
0.0387s