Chapter 17: Advanced C++ Topics I

Chapter Goals

Operator Overloading

Syntax 17.1: Overloading Operator Definition

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.

Operator Overloading (overload.cpp)

Operator Overloading


Automatic Memory Management

Syntax 17.2: Destructor Definition

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 (department.cpp)