Function overloading defines two or more functions in the same scope with the same name but different signatures. The C++ compiler selects a function from the call’s arguments. section 7.1.2 section 7.6
Use overloading when functions perform closely related operations:
- Overload member or standalone functions when separate names would obscure their strong relationship. section 7.1.2
- Keep overloaded operations conceptually similar, identical, or equivalent. section 7.1.2
- Distinguish signatures by parameter number, datatypes, or order—not parameter names or return type. section 7.6
One name, different inputs
A drawing interface can offer draw_circle(int x, int y, double radius) and draw_circle(Point p, double radius). Similarly, print(Textfile f) and print(Textfile f, PDF p) express related printing operations.
enum class Kind
{
FICTION, COOKBOOK, HOWTO
};
inline ostream& operator <<(ostream& ostr, const Kind& k)
{
switch (k)
{
case Kind::FICTION: ostr << "fiction"; break;
case Kind::COOKBOOK: ostr << "cookbook"; break;
case Kind::HOWTO: ostr << "howto"; break;
}
return ostr;
}
Browse an overloaded output operator that converts Kind values into readable strings for cout. section 7.1.2


