CSE 250 Lecture Notes - Lecture 14: Disk Array

87 views3 pages

Document Summary

Our assignment operator and copy constructor for csevector creates a copy of everything from v1. push_back(i); the other object: //adds (cid:858)(cid:1005)(cid:1004)(cid:859) to (cid:448)(cid:1005) -> does(cid:374)(cid:859)t (cid:272)ha(cid:374)ge (cid:448)(cid:1006) v1. push_back(10); Deep copy copies everything, including allocated memory. //makes entirely new copy of v1, named v2 (now have 2. The default assignment operator/copy constructor would have the following behavior: v1. push_back(i); Csevector v1; for (int i = 0; i < 5; ++i) { If we try to access the element at index 5 of v2, we will have an index out of bounds error, even though there(cid:859)s te(cid:272)h(cid:374)i(cid:272)ally so(cid:373)ethi(cid:374)g there i(cid:374) (cid:373)e(cid:373)ory. //size is changed for v1, but not v2; we only called push_back on v1 so. //that is the only thing whose size is updated. //assigns v2 to the same memory as v1. Same pointer => anytime one is changed, it changes for both of them, but the state of the two differ.

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