Method Overloading - Cmartinez-28/2143-OOP GitHub Wiki

Definition

The ability to create multiple methods of a class that share the same name of the class but have different parameter lists. It is a type of static polymorphism solved at compile-time.

Purpose

Method overloading allows a single method name to perform different tasks based on the parameters provided. It can be used to create multiple constructors, the one that matches the parameter list is used.

Code Example

Class Employee
{
   int ID;
   string name;
public:
   //same name, different parameter lists
   Employee();
   Employee(int, string);
}

Common Mistakes

  • Thinking variable names are required when creating constructors
  • Not creating enough constructors for the different ways the class can be used

Related Concepts

  • Classes
  • Polymorphism
  • Operator Overloading