home *** CD-ROM | disk | FTP | other *** search
- // 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;
- }