Advertisement
MeehoweCK

Untitled

Feb 10th, 2021
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. // wskaźnik dzielony
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     shared_ptr<int> sptr(new int);
  11.     shared_ptr<int> sptr2;
  12.  
  13.     cout << "sptr: " << sptr.use_count() << "\tsptr2: " << sptr2.use_count() << endl;
  14.     sptr2 = sptr;
  15.     cout << "sptr: " << sptr.use_count() << "\tsptr2: " << sptr2.use_count() << endl;
  16.  
  17.     {
  18.         shared_ptr<int> sptr3 = sptr;
  19.         cout << "sptr: " << sptr.use_count() << "\tsptr2: " << sptr2.use_count() << endl;
  20.     }
  21.  
  22.     cout << "sptr: " << sptr.use_count() << "\tsptr2: " << sptr2.use_count() << endl;
  23.  
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement