CS 112 - Week 8 Lecture 1 - 2022-10-11
TODAY WE WILL:
* announcements
* continuing STOP 7 - dynamic memory and classes,
(and when you need the "big 3"
and how to write them)
* prep for next class
=====
* next reading:
Savitch, Ch. 11, Section 11.4: Classes and Dynamic Arrays
* when a class has data fields that are all scalar
and static, the default destructor method,
overloaded assignment operator method,
and copy constructor method all work fine.
* static memory goes away properly when a function
or method or program ends,
* copying an object copies its data fields values
to the other object
* note: the copy constructor method for a class
is called by the operating system in situations
where a copy of the object is needed --
for example, pass-by-value arguments!
=====
ASIDE:
=====
* typically, when you create a class,
each object of that class gets its own copies
of ALL of the data fields;
IF you have a data field where you want just ONE
copy ever, no matter how many objects of that class
exist,
you can declare it as static
static const int DEFAULT_SIZE = 4;
* this is not limited to data fields, either...