Guest User

Untitled

a guest
Jun 25th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. Point p1 = Point(0,0);
  2.  
  3. Point* p1 = new Point(0, 0);
  4.  
  5. void foo()
  6. {
  7. Point p = Point(0,0);
  8. } // p is now destroyed.
  9.  
  10. for (...)
  11. {
  12. Point p = Point(0,0);
  13. } // p is destroyed after each loop
  14.  
  15. class Foo
  16. {
  17.  
  18. Point p;
  19. }; // p will be automatically destroyed when foo is.
  20.  
  21. void foo(int size)
  22. {
  23. Point* pointArray = new Point[size];
  24. ...
  25. delete [] pointArray;
  26. }
  27.  
  28. void SomeFunc()
  29. {
  30. Point p1 = Point(0,0);
  31. } // p1 is automatically freed
  32.  
  33. void SomeFunc2()
  34. {
  35. Point *p1 = new Point(0,0);
  36. delete p1; // p1 is leaked unless it gets deleted
  37. }
  38.  
  39. Point p1 = Point(0,0); //This is if you want to be safe and don't want to keep the memory outside this function.
  40.  
  41. Point* p2 = new Point(0, 0); //This must be freed manually. with...
  42. delete p2;
Add Comment
Please, Sign In to add comment