O'Reilly logo

The C++ Programming Language, Fourth Edition by Bjarne Stroustrup

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8. Structures, Unions, and Enumerations

Form a more perfect Union.

– The people

Introduction

Structures

struct Layout; struct Names; Structures and Classes; Structures and Arrays; Type Equivalence; Plain Old Data; Fields

Unions

Unions and Classes; Anonymous unions

Enumerations

enum classes; Plain enums; Unnamed enums

Advice

8.1. Introduction

The key to effective use of C++ is the definition and use of user-defined types. This chapter introduces the three most primitive variants of the notion of a user-defined type:

• A struct (a structure) is a sequence of elements (called members) of arbitrary types.

• A union is a struct that holds the value of just one of its elements at any one time.

• An enum (an enumeration) is a type with a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required