EECS 280 Lecture Notes - Lecture 16: Object Copying, Dynamic Array

55 views8 pages

Document Summary

If you have an array in the heap, you have to erase it by: delete[] elts; If you don"t use the [], it"ll be undefined. Foo(s); // makes a pointer to the same thing that unordered_set is pointing to in the heap. //but after this code runs, it deletes what"s in the heap when the destructor runs. S. query(5); //this can"t run because what"s in the heap has been erased. A copy constructor customizes how a class is copied. Is the same thing as = unordered_set t(s); Keep in mind that the code for the copy constructor is not inside of the foo function. What happens is that the compiler sees that we"re making a copy and automatically uses the code we have written inside of our copy ctor inside of the class. The copy ctor has to initialize member variables and copy everything. For (int i = 0; i < elts_size; ++i) {

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