Chapter 11: Inheritance I

Chapter Goals

Derived Classes

Syntax 11.1 Derived Class Definition

Syntax 11.1 : Derived Class Definition

class Derived_class_name : public Base_class_name
{
features
};
Example:
class Manager : public Employee
{
public:
Manager(string name, double salary, string dept);
string get_department() const;
private:
string department;
};
Purpose: Define a class that inherits features from a base class.

Derived Classes

Derived Classes (clocks1.cpp)

Derived Classes

Calling the Base-Class Constructor

Syntax 11.2 Constructor with Base-Class Initializer

Syntax 11.2 : Constructor with Base-Class Initializer

Derived_class_name :: Derived_class_name(expressions)
: Base_class_name(expressions)
{
statements
}
Example:
Manager::Manager(string name, double salary, string dept)
: Employee(name, salary)
{
department = dept;
}
Purpose: Supply the implementation of a constructor, initializing the base class before the body of the derived-class constructor.

Calling Base-Class Member Functions

Calling Base-Class Member Functions (clocks2.cpp)