At the most basic level, a data structure is a way to group together related data elements and a strategy for using those data. As one example, our Sales_item
class groups an ISBN, a count of how many copies of that book had been sold, and the revenue associated with those sales. It also provides a set of operations such as the isbn
function and the >>
, <<
, +
, and +=
operators.
In C++ we define our own data types by defining a class. The library types string
, istream
, and ostream
are all defined as classes, as is the Sales_item
type we used in Chapter 1. C++ support for classes is extensive—in fact, Parts III and IV are largely devoted to describing class-related features. Even though the Sales_item
class is pretty simple, we won’t be able to fully define that class until we learn how to write our own operators in Chapter 14.