CIS 181 Intro to Comp Sci
Class 24, May 5, 2005
IMPORTANT DATES:
Fourth Project due: Tuesday May 17th
Final Exam Scheduled for Friday, May 20th, 10:30am-12:30pm
ASSIGNMENT:
Read D&D, in Chapter 8, pages 546-582
Exercise Due Tuesday, May 10
Exercise 8.8, Page 600 (see website for string class files)
TODAY'S TOPICS
-
embedded classes -- see figure 7.6-- especially initialization of
embedded classes in constructor
-
Operator Overloading
See the files:
$CLASSHOME/examples/rational-overload.h
$CLASSHOME/examples/rational-overload.cc
$CLASSHOME/examples/rational-overload-driver.cc
-
Operator overloading allows more concise (and clearer) notation
when using user defined classes
-
Operators overloaded by writing a function definition using
special keyword operator followed by the symbol for the operator
being overloaded (for the function name)
-
Overloaded operators may be either member functions or friend
functions. If a member function, leftmost operand must be a
class object (or reference to a class object).
-
Overloading an operator does not change the fundamental
properties of the operator (e.g., number of arguments,
precedence).
-
Stream insertion and stream extraction operators (<<, >>) can
be overloaded to perform I/O for user defined types. Because
the stream itself is the left-most argument, these must be
overloaded as friends.