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 ...

Get Core C++ A Software Engineering Approach 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.