<<== <= [table of contents] [search] [glossary] [feedback] =>==>>

[online C++ tutorial]Section 5: Functions

Section 5.5: Function Overloading

Function overloading involves writing two or more functions that have the same name, but different parameter lists. Then, during execution of a program, picking which of the functions to use is left up to the compiler, and is based on the parameters that have been passed to the function.

For instance, let's say we have a Color Object, a Shape Object, and a Texture Object. Instead of formally explaining the objects, let's just say they can have the following values:

Color Shape Texture
Blue Square Smooth
Red Circle Rough
Green Ellipse Bumpy

When using these objects it would be nice to be able to generate random combinations and be able ...

Color Increment(Color old_color){
   if (old_color == Blue)
      return Red;
   if (old_color == Red)
      return Green;
   if (old_color == Green)
      return Blue;
   return Blue;
}

Shape Increment(Shape old_shape)



<<== <= [table of contents] [search] [glossary] [feedback] =>==>>