Home Segments Index Top Previous Next

169: Mainline

Once you have introduced a function's prototype, you can define the function outside of the class definition. Note, however, that C++ requires you to indicate to which class such an externally defined function belongs by prefixing the function name with the class name and two colons:

class box_car {
  public: double height, width, length;
          double volume ( );       
};
double box_car::volume ( ) {       
  return height * width * length;  
}                                  

The class names and colons preceding the member-function definitions have two purposes:

The colons are called the class-scope operator.