UNDERSTANDING CLASSES

A class is a specification of a data type that you define. It can contain data elements that can either be variables of the fundamental types or of other user-defined types. The data elements may be single data items, arrays, pointers, arrays of pointers of almost any kind, or objects of other class types, so you have a lot of flexibility. A class typically contains functions that operate on objects of the class type by accessing the data elements that they include. So, a class combines both the definition of the elementary data that makes up an object and the means of manipulating the data that belongs to objects of the class type.

The data and functions within a class are called members of the class. Oddly enough, the members of a class that are data items are called data members and the members that are functions are called function members or member functions. The member functions of a class are also sometimes referred to as methods; I will not use this term, in general, in this book, but it will turn up in Chapter 18.

When you define a class, you define a blueprint for objects of that type. This doesn’t actually define any data, but it does define what the class name means, that is, what an object of the class type will consist of and what operations can be performed on such an object. It’s much the same as if you wrote a description of the basic type double. This wouldn’t be an actual variable of type double, but a definition of how it’s made up and ...

Get Ivor Horton's Beginning Visual C++ 2012 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.