Home Segments Index Top Previous Next

172: Mainline

At this point, you have seen that you can define volume as an ordinary function with one explicit parameter, a particular box_car object. You refer to the box_car object's member variables using class-member operators:

double volume (box_car b) { 
  return b.height * b.width * b.length; 

Thus defined, volume is called with an argument that is a particular box_car object:

volume (x) 

You can also define volume as a member-function with no explicit parameter:

double volume ( ) { 
  return height * width * length; 

Remember that, by convention, the member-variable values used in this definition of volume are the values associated with a particular box_car object—the one that is identified by the box_car variable that appears joined, via the class-member operator, to the function call:

x.volume ( )