home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C Programming Starter Kit 2.0
/
SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso
/
tybc4
/
overload.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-17
|
893b
|
44 lines
// C++ program illustrates function overloading
#include <iostream.h>
// inc version for int types
void inc(int& i)
{
i = i + 1;
}
// inc version for double types
void inc(double& x)
{
x = x + 1;
}
// inc version for char types
void inc(char& c)
{
c = c + 1;
}
main()
{
char c = 'A';
int i = 10;
double x = 10.2;
// display initial values
cout << "c = " << c << "\n"
<< "i = " << i << "\n"
<< "x = " << x << "\n";
// invoke the inc functions
inc(c);
inc(i);
inc(x);
// display updated values
cout << "After using the overloaded inc function\n";
cout << "c = " << c << "\n"
<< "i = " << i << "\n"
<< "x = " << x << "\n";
return 0;
}