Defining our own data structures Class definition must have ; at the end. Preprocessor The most common technique for making it safe to include a header multiple times relies on the preprocessor. #include Header guards #ifndef SALES_DATA_H #define SALES_DATA_H #include struct Sales_data { std::string bookNo; unsigned units_sold = 0; double revenue = 0.0; }; #endif SALES_DATA_H can be any name, just it has to be unique throughout the program. preprocessor variables usually are written in all uppercase.
Dealing with Types type alias typedef double wages; // wages is a synonym for double typedef wages base, *p; // base is a synonym for double, p for double* C++11: alias declaration using SI = Sales_item; // SI is a synonym for Sales_item As usual, a const that appears in the base type modifies the given type. The type of pstring is “pointer to char.” So, const pstring is a constant pointer to char—not a pointer to const char. It can be tempting, albeit incorrect, to interpret a declaration that uses a type alias by conceptually replacing the alias with its corresponding type. typedef char *pstring; const pstring cstr = 0; // cstr is a constant pointer to char const pstring *ps; // ps is a pointer to a constant pointer to char const char *cstr = 0; // wrong interpretation of const pstring cstr C++11: auto. auto tells the compiler to deduce the type from the initializer. The initializers for all the variables in the declaration using auto must have types that a...