CS14 Lab 2
Week of October 8—12
We're going to be writing a lot of code this quarter,
and most of it will
be C++ classes. The environment is Linux, and the compiler is g++.
Makefiles are appreciated.
Use this lab period to review C++ classes, compiling and running in
Linux.
Following is a list of topics that you should be at least familiar with
in order to have a fighting chance this quarter.
If you feel competent in these topics, there is no need for you to go to
lab this week.
Classes
declaration
definition (implementation)
division into separate files
data members -- declaration
data members -- initialization (not in class definition)
data members -- how to access
member functions -- writing
member functions -- calling
public & private
the scope opertor ::
constructor
destructor
inline functions
accessor methods (return value of private data)
mutator methods (change value of private data)
memberwise copy with assignment
objects as data members
Copy constructors
when used
automatic
copies (value parameters)
return values
explicit
declaration and initialization in the same statement
to make a copy of an object:
A.List(B); will make A be a copy of B
List A(B); will create A and place a copy of B in A.
why use
when object contains pointers
to avoid major problems when destructors are called
operator overloading
why do it?
keyword operator
which operators may be overloaded (don9t memorize all, but know
examples)
restrictions on overloading
how compiler translates overloaded operator
friend functions
overloading the insertion (<<) and extraction (>>) operators
must be done as friend function
takes ostream & as argument, returns ostream &
one other argumemt
Compiling with g++
flags
executable name
Makefiles
what they are
what they do
how to use
labels