Advertisement
STANAANDREY

shared ptr ex

Sep 27th, 2024
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <memory>
  3. #include <future>
  4. using namespace std;
  5. using Pii = pair<int, int>;
  6.  
  7. void printPair(const Pii &pii) {
  8.     cerr << pii.first << ' ' << pii.second << endl;
  9. }
  10.  
  11. int main() {
  12.     auto sp = make_shared<Pii>(1, 2);
  13.     shared_ptr<Pii> sp2 = sp;
  14.     printPair(*sp2);
  15.     cerr << sp.use_count() << endl;
  16.     cerr << sp.get() << endl;
  17.  
  18.     return 0;
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement