CS 162 Lecture Notes - Lecture 11: Operand, Local Variable
CS 162 – Lecture 11 – Big 3 Activity
Constructor
o Prototype:
▪ ClassName();
▪ ClassName(w/params);
o Job:
▪ Build the object
o When is it called?
▪ Default is called when object is declared if no parameters are given.
Nondefault is called if parameters are given
o Default behavior if not defined
▪ Will declare all variables with garbage values, will not set up pointers
o Reminders
▪ If any constructor is defined then the compiler will not provide one, even
if a default constructor is not defined
Copy Constructor
o Prototype
▪ ClassName(const ClassName&);
o Job
▪ Copies the contents of the passed in object to the destination object.
o When is it called?
▪ Pass by value
▪ Return value
▪ When initializing an object with this constructor
o Default behavior if not defined
▪ Shallow copy, will only copy over the values stored in each variable
o Reminders
▪ Works with objects that can be assumed to be unitialized
Assignment Operator Overload
find more resources at oneclass.com
find more resources at oneclass.com