onilink_

pointers

Jan 7th, 2016
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1.     // --- unique_ptr ---
  2.     T unique uptr(new T); // std::unique_ptr<T> uptr(std::make_unique<T>());
  3.     uptr = T();           // *uptr = T();
  4.     uptr.foo();           // uptr->foo();
  5.     uptr->reset(new T);   // uptr = std::make_unique<T>();
  6.     (@uptr).reset(new T); // uptr = std::make_unique<T>();
  7.     (*@uptr).foo();       // uptr->foo();
  8.  
  9.     // --- pointeur ---
  10.     int x(123), y(456);
  11.     int& ref(x); // int* ref = &x;
  12.     ref = 345;   // *ref = 345;
  13.     @ref = @y;   // ref = &y;
  14.     assert(ref isnot null); // assert(ref != nullptr)
  15.    
  16.     // --- pointer X unique_ptr ---
  17.     T& ptr(uptr);
  18.     @ptr = @uptr;
Advertisement
Add Comment
Please, Sign In to add comment