Structures as Heterogeneous Aggregates

The next programmer-defined aggregate data types on our agenda are structures. C++ structures are a powerful aggregation tool for combining related components. There is more than one method to define a structure in C++, and we will discuss the most popular ones. All methods allow the programmer to define structure components (fields, or data members), that is, to list the types and names of the components.

Defining Structures as Programmer-Defined Types

The structure definition starts with the keyword struct followed by the programmer-defined name that will be used as a type name to define variables in the program. The structure fields are declared within scope curly braces followed by a semicolon. Each ...

Get Core C++ A Software Engineering Approach 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.