CS 162 Lecture Notes - Lecture 9: Member Variable, Memory Management

23 views2 pages
CS 162 Lecture 9 Intro to the Big 3
Destructor
o Deletes the object
o Will be automatically created if one is not supplied
Will not handle dynamic memory
o ~Class_Name();
no return type, no parameters, only one allowed
o Called when the object goes out of scope
When the function ends
When the program ends
A block containing local variables ends
A delete operator is called
Shallow Copy vs. Deep Copy
o Shallow
Copy the contents of member variables from one object to another
Default for assignment operator and copy constructor
o Deep
Copy what each member variable is pointing to so that you get a separate
but identical copy
Has to be programmer specified
Copy Constructor
o Constructor that has one parameter that is of the same type as the class
Has to be call be reference (normally const)
Allows for distinct copies, changes to one does not impact the other
Called automatically in three cases:
When a class object is being declared and initialized by another
object of same type
When a function returns a value of the class type
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents