Overloading

Functions in C

In C, everything is simple

  • A function has a name

  • The name is the only thing by which functions are distinguished

  • Not the return type, nor the paraameters

Declaration of x
int x(int i);
Ok
int ret = x(42);
2x Error
char *ret = x("huh?");
Error: x declared twice
char *x(char* str);

Functions in C++ — Overloading

C++: better

Two declarations of x
int x(int i);
char *x(const char *str);
Ok
int ret = x(42);
Ok
char *ret = x("huh?");
Error: no appropriate x found
char *ret = x(42);