Function overloading

From Tux
Revision as of 18:59, 23 January 2018 by Williams (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Function overloading is a form of polymorphism (identical symbols doing different things in context) in which multiple functions with the same name can be written, subject to certain restrictions. The primary restriction is that functions can be overloaded only if there is not a matching function that takes the same number of and type of parameters.

// Given the following function (stated as a prototype)
int fcn(int, int);

// The following functions can be written in the same program:
int fcn(int);
int fcn(int, int, int);
int fcn();
int fcn(double, int);
int fcn(int, double);

// The following functions cannot be written in the same program:
int fcn(int, int);
double fcn (int, int);
void fcn(int, int);