© Will Briggs 2019
Will BriggsC++ for Lazy Programmershttps://doi.org/10.1007/978-1-4842-5187-4_15

15. Classes

Will Briggs
Lynchburg, VA, USA
Till now what we’ve covered has been essentially C with a few tweaks, notably cin and cout. Now it’s time to add the thing that puts the + in C++: classes.

Writing classes

Here’s a class type to store a calendar date.
class Date
      int days_;
      int months_;
      int years_;
Date arrival;//Variables of a class type are called "objects"
             //Using the term makes you sound smart at job interviews
We could have done that with a struct. As with structs, we can declare variables of this type, pass them as parameters, get at the parts with “ . ”, and so on – it looks much the same. But we’re about ...

Get C++ for Lazy Programmers: Quick, Easy, and Fun C++ for Beginners now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.