Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. window = unique_ptr<SDL_Window, decltype(free) *>
  2. reinterpret_cast<SDL_Window *>(malloc(sizeof(SDL_Window))),
  3. free};
  4.  
  5. &window.get()
  6. // or
  7. &&(*window)
  8. // or
  9. &window
  10. // and even
  11. &(&(*(window.get())))
  12.  
  13. SDL_Window *window_ptr;
  14. unique_ptr<SDL_Window> window;
  15.  
  16. window = unique_ptr<SDL_Window, decltype(SDL_DestroyWindow)> (
  17. window_ptr,
  18. SDL_DestroyWindow);
  19.  
  20. SDL_CreateWindowAndRenderer(500, 500, SDL_WINDOW_SHOWN, &window_ptr, &renderer_ptr);
  21.  
  22. /usr/include/c++/5/bits/unique_ptr.h:272:18: error: no match for ‘operator=’
  23. (operand types are ‘std::unique_ptr<SDL_Window>::deleter_type
  24. {aka std::default_delete<SDL_Window>}’ and ‘void (*)(void*)’)
  25. get_deleter() = std::forward<_Ep>(__u.get_deleter());
  26.  
  27. SDL_Window *window_;
  28. SDL_Renderer *renderer_;
  29. SDL_CreateWindowAndRenderer (/* ... */, &window_, &renderer_);
  30. unique_ptr<SDL_Window, decltype(&SDL_DestroyWindow)>
  31. window(window_, &SDL_DestroyWindow);
  32.  
  33. std::unique_ptr<myclass> uptr;
  34.  
  35. myclass*& inside = *reinterpret_cast<myclass**>(&uptr);
  36.  
  37. #include <iostream>
  38. #include <memory>
  39.  
  40. class myclass {
  41. public:
  42. myclass() {
  43. }
  44. ~myclass() {
  45. std::cout << "It works!n";
  46. }
  47. };
  48.  
  49. int main()
  50. {
  51.  
  52. std::unique_ptr<myclass> uptr;
  53.  
  54. myclass*& inside = *reinterpret_cast<myclass**>(&uptr);
  55.  
  56. inside = new myclass();
  57.  
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement