Chapter 4 Introduction to Classes

The most important feature of C++ is its support for user-defined types, through a mechanism called “classes.” Classes are far more powerful than the user-defined types you can create in C. While an instance of a built-in type is called a variable, an instance of a class is called an “object,” hence the phrase “object-oriented programming.” Part 2 of this book describes classes, and Part 3 describes object-oriented programming.

This chapter covers the following topics:

Declaring a class

Using objects of a class

Data members and member functions

Constructors and destructors

const objects and member functions

Member objects

Header and source files

Before explaining how to define a class in C++, let's consider one way you can create a new data type in C.