Guest User

Untitled

a guest
Oct 27th, 2022
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include<iostream>
  2. #include<memory>
  3.  
  4. using namespace std;
  5.  
  6. class Obj {
  7.     int some_unique_data_ptr_;
  8. public:
  9.     Obj() : some_unique_data_ptr_(0) {}
  10.     Obj(const Obj& o) : some_unique_data_ptr_(o.some_unique_data_ptr_+1) {}
  11.     Obj(Obj&& o) : some_unique_data_ptr_(o.some_unique_data_ptr_) {}
  12.    
  13.     operator int(){ return some_unique_data_ptr_; }
  14. };
  15.  
  16. int main(){
  17.     unique_ptr<Obj> A = make_unique<Obj>();
  18.     unique_ptr<Obj> B = make_unique<Obj>(*A);
  19.    
  20.     cout << static_cast<int>(*A) << endl;
  21.     cout << static_cast<int>(*B) << endl;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment