Writing Classes

The rational type is an example of a class. Now that you’ve seen a concrete example of writing your own class, it’s time to understand the general rules that govern all classes. This Exploration and the next four lay the foundation for this important aspect of C++ programming.

Anatomy of a Class

A class has a name and members—data members, member functions, and even member typedefs and nested classes. You start a class definition with the struct keyword. (You might wonder why you would not start a class definition with the class keyword. Please be patient; all will become clear in Exploration 35.) Use curly braces ...

Get Exploring C++ 11, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.