-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctionOverloading.cpp
54 lines (44 loc) · 1.24 KB
/
FunctionOverloading.cpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
- In Function Overloading two or more functions have same name with different parameters.
- Function Overloading enhances the clarity and organization of code.
- Function Overloading comes under Compile time polymorphism.
*/
#include<iostream>
using namespace std;
class myClass{
public:
void fun()
{
int i = 89;
cout<<"The value of i is:"<<i<<endl;
}
//Function Overloading with different parameter
void fun(int k, char c)
{
cout<<"I am function overloading with formal parameter."<<endl;
cout<<"The value of k is:"<<k<<endl;
cout<<"The value of c is:"<<c<<"\n";
}
void fun(int a, int b = 89)
{
cout<<"I am function overloading with default parameter"<<endl;
cout<<"The value of a is:"<<a<<endl;
cout<<"The value of b is:"<<b<<endl;
}
void he(int c, int d = 67)
{
cout<<"I'm not function Overloading"<<endl;
cout<<"Overriding the default value"<<endl;
cout<<"The value of c is:"<<c<<endl;
cout<<"The value of d is:"<<d<<endl;
}
};
int main(){
myClass f;
f.fun();
f.fun(4, 'r');//actual parameter
f.fun(5);
//the below code will override the value of d
f.he(6, 56);
return 0;
}