© Will Briggs 2021
W. BriggsC++20 for Lazy Programmershttps://doi.org/10.1007/978-1-4842-6306-8_15

15. Classes

Will Briggs1  
(1)
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. They won’t give us new abilities like cin/cout, SSDL functions, or control structures like loops. What they will do is help us keep things organized so we don’t get confused; minimize errors; and make expressing things simpler – so we can trust the code we write and use it for bigger and better projects.

As an example, here’s a class type to store a calendar date:
class Date
{
    int day_;
    int month_;
    int year_;
};
...
Date appointment; // Variables ...

Get C++20 for Lazy Programmers: Quick, Easy, and Fun C++ for Beginners 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.