Classes with Object Members

Let's begin with classes that include class objects as members. Some classes, such as the String class of Chapter 12, “Classes and Dynamic Memory Allocation,” or the standard C++ classes and templates of Chapter 16, “The string Class and the Standard Template Library,” offer convenient ways of representing components of a more extensive class. We'll look at a particular example now.

What is a student? Someone enrolled in a school? Someone engaged in thoughtful investigation? A refugee from the harsh exigencies of the real world? Someone with an identifying name and a set of quiz scores? Clearly, the last definition is a totally inadequate characterization of a person, but it is well-suited for a simple computer representation. ...

Get C++ Primer Plus, Fourth Edition now with O’Reilly online learning.

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