Classes
My next task is to describe the syntax for combining functions with data into an aggregate data type. C++ supports this by providing the struct and class keywords and the rules for merging components into an aggregate that can be handled as a whole. In the class definition, you specify the types and the names of the data members (data fields) and the headers or the bodies of member functions (that access these data fields). The class name can be used by client code as a type name. This means that we can define variables of this type (objects), pass them as parameters to functions, and so on.
Let us consider representing time of day as a combination of hours and minutes. We want to have an object that can store time data and display the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access