CMPT 225 Lecture Notes - Lecture 2: Memory Management, Object Copying, Memory Leak

26 views4 pages

Document Summary

Write a new copy constructor that will create a deep copy. Need to give it an object of the same type as the type i"m building const means that the parameter i"m passing can"t change - copy constructor can"t accidentally destroy thing i am making a copy of. & passes by reference (not making a copy when we pass it to copy constructor, just giving it address) Mystack::mystack(const mystack & st) n = st. n; top = st. top; Resposible for cleaning up any dynamic memory associated with an object. Much like in push, want to delete array so we don"t cause a memory leak. Never explicitly call a destructor, they are called for you. Basically just example of writing a function that will return a stack. void assigntest() Mystack st = stack123(); cout << st. pop() << endl; cout << st. pop() << endl; cout << st. pop() << endl; It doesn"t work and just spits out garbage values!

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