Chapter 2. Classes

This chapter provides an introduction to classes and objects, and how member functions operate on objects. UML is introduced. static and const members are explained. Constructors, destructors, copy operations, and friends are discussed.

2.1

Structs

48

2.2

Class Definitions

49

2.3

Member Access Specifiers

51

2.4

Encapsulation

54

2.5

Introduction to UML

54

2.6

Friends of a Class

55

2.7

Constructors

56

2.8

Subobjects

58

2.9

Destructors

60

2.10

The Keyword static

61

2.11

Copy Constructors and Assignment Operators

64

2.12

Conversions

67

2.13

const Member Functions

68

Structs

In the C language, there is the struct keyword, for defining a structured chunk of memory.

Example 2.1. src/structdemo/demostruct.h

[ . . . . ] struct Fraction { int numer, denom; string description; ...

Get An Introduction to Design Patterns in C++ with Qt 4 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.