Chapter 4. Structures

In This Chapter

Structures 132

Enumerations 148

We’ve seen variables of simple data types, such as float, char, and int. Variables of such types represent one item of information: a height, an amount, a count, and so on. But just as groceries are organized into bags, employees into departments, and words into sentences, it’s often convenient to organize simple variables into more complex entities. The C++ construction called the structure is one way to do this.

The first part of this chapter is devoted to structures. In the second part we’ll look at a related topic: enumerations.

Structures

A structure is a collection of simple variables. The variables in a structure can be of different types: Some can be int, some ...

Get Object-Oriented Programming in C++, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.