Function overloading

Languages which support function overloading include, but are not necessarily limited to, the following: Languages which does not support function overloading include C, Rust and Zig.

Constructors, used to create instances of an object, may also be overloaded in some object-oriented programming languages.

[11] For example, a default constructor for a restaurant bill object written in C++ might set the tip to 15%: The drawback to this is that it takes two steps to change the value of the created Bill object.

Which one gets used depends on the number of parameters provided when the new Bill object is created (none, or two): Now a function that creates a new Bill object could pass two values into the constructor and set the data members in one step.

The following shows creation and setting the values: This can be useful in increasing program efficiency and reducing code length.

Another reason for constructor overloading can be to enforce mandatory data members.

In this case the default constructor is declared private or protected (or preferably deleted since C++11) to make it inaccessible from outside.

Two issues interact with and complicate function overloading: Name masking (due to scope) and implicit type conversion.