Chapter 7. Classes and Objects

One of the central features of C++ is that of classes, the single most important ability that C++ adds to C. There are many ways to think of a class. One of the best ways is this: A class is a user-defined type. Once you declare it, you can use it just as you would int, char, or double.

By declaring a class, you create a fundamental new data type, extending C++ itself. You can, if you choose, define how the type responds to operators (such as +, -, or <). You can also provide services in the form of member functions, effectively creating intelligent data types. An object “knows” how to respond to function calls and retains that knowledge even when it is accessed through a pointer of a more general type. (This is ...

Get C++ for the Impatient 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.