2.6.1. Defining the Sales_data Type

Image

Although we can’t yet write our Sales_item class, we can write a more concrete class that groups the same data elements. Our strategy for using this class is that users will be able to access the data elements directly and must implement needed operations for themselves.

Because our data structure does not support any operations, we’ll name our version Sales_data to distinguish it from Sales_item. We’ll define our class as follows:

struct Sales_data {    std::string bookNo;    unsigned units_sold = 0;    double revenue = 0.0;};

Our class begins with the keyword struct , followed by the name of the class and ...

Get C++ Primer, Fifth 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.