smart pointer

  

#include<bits/stdc++.h>
using namespace std;
void swap(shared_ptr<int>a,shared_ptr<int>b)
     {
         int t;
          t=*a,*a=*b,*b=t;
     }
int main()
{
    /*auto_ptr; unique_ptr; shared_ptr;
    auto_ptr<int> p;
    auto_ptr<int> p2(p);
    auto_ptr<int> p3(new int(10));*/
    auto_ptr<string> p1(new string("there is only one point to me."));
    auto_ptr<string> p2;
    cout<<*p1<<endl;
    p2=p1;
    //cout<<*p1<<endl;
    cout<<*p2<<endl;
    auto_ptr<string> p3(p2);
    //cout<<*p2<<endl;
    cout<<*p3<<endl;

    unique_ptr<string> pl1(new string("auto"));
    unique_ptr<string> pl2;
    //unique_ptr<string> p3(p1);
    //p2=p1


     shared_ptr<int> p11(new int(9));shared_ptr<int> p22(p11);
     shared_ptr<int> p33(new(int)),p44(new int(8)),p55;
     cout<<*p11<<"   "<<*p44<<endl;  swap(p11,p44);  cout<<*p11<<"   "<<*p44<<endl;
     //cout<<*p11<<"  "<<*p22<<" "<<*p33<<"  "<<*p44<<"  "<<*p55<<endl;

 

}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324676794&siteId=291194637