When you define a class, you tell C++ about the variables that describe
the objects that belong to that class. Note that you also can define
functions that work with those objects. You might, for example, define a
volume
function that knows how to find values for any box-car
object's height
, width
, and length
variables, and that
knows how to use those values to compute the box-car object's volume.
Thus, in the following diagram, the box_car
class description
contains descriptions of variables and class-specific functions, whereas
the descriptions of particular box_car
objects contain variables
values.
*-----------------------------------------------* | Description of variables; | <-- Description of | for example, height, width, and length | the box_car | Description of class-specific functions; | class | for example, volume | *-----------------------------------------------* ^ ^ ^ | Instance of | Instance of | Instance of | | | *-------------* *-------------* *-------------* | height 10.5 | | height 10.5 | | height 10.5 | <-- Descriptions of | width 9.5 | | width 9.5 | | width 9.5 | particular | length 40.0 | | length 40.0 | | length 50.0 | box_car objects *-------------* *-------------* *-------------*