EECS 280 Lecture Notes - Lecture 14: Dynamic Array, Memory Management, Function Overloading

66 views6 pages

Document Summary

Inside function (block) or args anywhere you use new. With dynamic arrays, we can choose the size at runtime. Int *array = new int [ size ]; : numberofelements (0); // the : is called a member initializer list numberallocated(defaultnumberallocated) Elements = new int [numberallocated]; //this created the dynamic array. Two different functions with the same name, but different prototypes. Where a derived class has a function with the same name and prototype as the parent. To solve a memory leak that occurs with a constructor, we need to call delete when an unordere is destroyed. To do so we use a destructor, which calls delete. Destructors run automatically when an object is destroyed. > the problem with this example above is that you"re creating something without a name, not deleting it -- there is a memory leak. You"re responsible for managing the lifetime of an object. deredset me, and. You"re responsible for managing the lifetime of an object.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents