Chapter 3. C++ and Object-Oriented Programming

Table of Contents

Introduction
Classes in C++
Constructors
Constructors and Member Initialisation Lists
Classes and Pointers
Class Hierarchy
Static and Dynamic Types
Abstract Classes
C++ Explicit Casts
Method Parameters
Default Parameters
Constant Parameters
Over-Loading
Operator Overloading
Destructors
Multiple Constructors
The copy constructor
Separate Compilation
Dynamic Creation of Objects
Arrays of Objects
Multiple Inheritance
Friend Methods
Static States of Classes
More Scope Resolution Operations
Structs in C++
Unions in C++
Non-Virtual Methods
Inline Methods:
Full Source Code Examples
The Account Class
The Account and CurrentAccount Classes
Multiple Inheritance Example (with problems)
The Multiple Inheritance Example Fixed
A Final Working Version of the Cashsave example
Friend Methods, Pointers to Objects and Destructors
Now with a Copy Constructor!
Destructors and Arrays.
Exercise
 

"The problem with using C++ ... is that there's already a strong tendency in the language to require you to know everything before you can do anything."

 
 --Larry Wall

Introduction

We discussed the general concepts of classes and objects in the section called “Introduction to Object-Oriented Programming”, now it is time to apply these concepts using the C++ language.