1 2 3 4 5 6 7 8 9 10 11 12

An obvious example might be

int power (int x, int y);
double power (double x, double y);
or
sort (int N, char* s);
sort (int N, int* i);
sort (int N, double* r);// well, perhaps not!

Because of this overloading of the identifier sortwe will need three constructors and three destructors.

Overloading is also useful for initialization purposes in classes. Consider

class String {
public:
String (const char* s);// constructor
String () { text = ""; len = 0; }// overloading
~String () { delete [] text; }
.......
private:
char* text;
int len;
};
with the general constructor declared as:
String :: String (const char* s)
{
len = strlen(s);
text = new char[len+1];
strcpy(text, s);
}

March 11, 1998

Page 7

C201/TAM