smart pointer 示例程序

 

使用方法:

unique_ptr<string> ps1(new string("hello")); 
shared_ptr<vector<int>> ps2(new vector<int>(3));  //(*ps2).size() = 3;
weak_ptr <vector<int>> ps5(ps2), ps6;   //初始化weak_ptr的方法
ps6 = ps2;
shared_ptr<int> ps3 = make_shared<int>(4);    //*ps3 = 4;
auto ps4 = make_shared<int>(5);           //ps4的类型为 shared_ptr<int>

 

posted @ 2020-12-22 19:51  zeroPatrick  阅读(41)  评论(0编辑  收藏  举报