Chapter 17: Advanced C++ Topics I

Lecture Goals

Operator Overloading

Operator Functions

Syntax 17.1: Overloading Operator Definition

return_type operatoroperator_symbol(parameters)
{

statements
}
Example:
int operator-(Time a, Time b)
{
return a.seconds_from(b)
}
Purpose: Supply the implementation of an overloaded operator.

Overloading Comparison Operators

Input and Output

Operator Overloading (overload.cpp)

Overloading Increment and Decrement Operators

Operator Members

Operator Overloading (overload1.cpp)


Automatic Memory Management

Automatic Memory Management (Destructors)

Syntax 17.2: Destructor Definition

Class_name::~Class_name()
{

statements
}
Example:
Department::~Department()
{
delete receptionist;
}
Purpose: Supply the implementation of a destructor that is invoked whenever and object goes out of scope.

Automatic Memory Management (Overloading the Assignment Operator)

Automatic Memory Management (Copy Constructor)

Automatic Memory Management (department.cpp)