forked from coder2hacker/Explore-open-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFriend_function_of_multiple_class1.cpp
82 lines (67 loc) · 1.25 KB
/
Friend_function_of_multiple_class1.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//Friend Function of multiple class
#include<iostream>
using namespace std;
class Second;
/*
Prorotype Declaration---->class Second;
Reason:
because we are using a friend funtion of multiple class,
so,when we going to declare compare function as friend of First &
Second,then at the time of declaration within First class still
class Second is not defined,So,if we don't write prototype
declaration the compiler will not identify what is "Second".
*/
class First
{
private:
int a;
public:
void take_val();
void display();
friend void compare(First,Second);
};
void First :: take_val()
{
cout<<"Enter value for a:\n";
cin>>a;
}
void First :: display()
{
cout<<"a= "<<a<<endl;
}
class Second
{
private:
int b;
public:
void take_val2();
void display2();
friend void compare(First,Second);
};
void Second::take_val2()
{
cout<<"Enter the value for b:\n";
cin>>b;
}
void Second :: display2()
{
cout<<"b= "<<b<<endl;
}
void compare(First F,Second S)
{
if(F.a>S.b)
cout<<"max:"<<F.a;
else
cout<<"Max:"<<S.b;
}
int main()
{
First F1;
F1.take_val();
F1.display();
Second S1;
S1.take_val2();
S1.display2();
compare(F1,S1);
return 0;
}