daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest Jul 12th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <memory>
  2.  
  3. struct Toto {
  4.   int a;
  5.   static void* operator new(size_t n)
  6.   {
  7.     return malloc(n);
  8.   }
  9.  
  10.   static void operator delete(void* ptr, size_t)
  11.   {
  12.     return free(ptr);
  13.   }
  14. };
  15.  
  16. int main(int argc, char** argv) {
  17.   std::unique_ptr<Toto> buf(new Toto{argc});
  18.   if (!buf) {
  19.     return 1;
  20.   }
  21.   printf("%d\n", buf->a);
  22.  
  23.  
  24.   std::unique_ptr<int, decltype(free)*> MyInt((int*)malloc(sizeof(int)), free);
  25.   if (!MyInt) {
  26.     return 1;
  27.   }
  28.   *MyInt = argc+10;
  29.   printf("%d\n", *MyInt);
  30.   return 0;
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top