Guest User

Untitled

a guest
Nov 1st, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <memory>
  4. #include <stdlib.h>
  5.  
  6. struct X {
  7.   X() { s1.reset(new char[32]); }
  8.   ~X() { printf("dtor\n"); }
  9.   void DoNothing() { printf("Hello\n"); }
  10.   void AcquireS2() { s2.reset(new char[64]); }
  11.  
  12.  std::unique_ptr<char[]> s1;
  13.  std::unique_ptr<char[]> s2;
  14. };
  15.  
  16. X* obj;
  17.  
  18. int main() {
  19.  obj = new X();
  20.  obj->AcquireS2();
  21.  obj->DoNothing();
  22.  printf("ptr: %p %p\n", obj->s1.get(), obj->s2.get());
  23.  return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment