EECS 280 Lecture Notes - Lecture 14: Dynamic Array, Memory Management, Function Overloading
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.