Function Overloading - Automatic Type Conversion

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream> // handles input and ouput statements
using namespace std;

void f(int x); 
void f(double x); // function prototypes

int main() {

	int i = 10;
	double d = 10.1;
	short s = 99;
	float r = 11.5;

f(i); // calls f(int)
f(d); // calls f(double)

f(s); // automatic type conversion function overload
f(r); // type conversion

cin.get(); // waits till the user presses enter
          // before closing the program


return 0;
}

void f(int x) {
	cout << "Inside f(int):" << x << "\n";
	 
}

void f(double x) {
	cout << "Inside f(double):" << x << "\n";
	
}
closed account (zb0S216C)
What am I looking at? What's your question?

Wazzak
Topic archived. No new replies allowed.