您当前的位置: 首页 >  ar

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

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

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             
关注
打赏
1688896170
查看更多评论
0.4597s