-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfriend_function.cpp
More file actions
89 lines (77 loc) · 1.3 KB
/
Copy pathfriend_function.cpp
File metadata and controls
89 lines (77 loc) · 1.3 KB
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
83
84
85
86
87
88
89
// #include <iostream>
// using namespace std;
// class sum{
// int a ,b;
// public:
// void setData(int x,int y){
// a=x;
// b=y;
// }
// void showData(){
// cout<<"The a = "<<a<<endl<<"The b = "<<b<<endl;
// }
// friend void fun(sum);
// };
// void fun(sum c){
// cout<<"Sum is : "<<c.a+c.b<<endl;
// }
// int main(){
// int s,d;
// cin>>s>>d;
// sum c1 ,c2;
// c1.setData(s,d);
// c1.showData();
// fun(c1);
// return 0;
// }
// *******************Use one friend to many classes**************
#include <iostream>
using namespace std;
// ****forword decleration***
class A;
class B
{
private:
int b;
public:
void get(int y)
{
b = y;
}
// friend void fun(A,B);
int showdata(A, A);
};
class A
{
private:
int a;
public:
friend int B::showdata(A, A);
void get(int x)
{
a = x;
}
// friend void fun(A,B);
};
int B::showdata(A o1, A o2)
{
return o1.a + o2.a;
}
// void fun(A o1,B o2)
// {
// cout<<"The sum is : "<<o1.a+o2.b<<endl;
// }
int main()
{
int x, y;
cin >> x >> y;
A c1, c3;
B c2;
c1.get(x);
c3.get(y);
// c2.get(y);
int sum = c2.showdata(c1, c3);
cout << "The sum is : " << sum << endl;
// fun(c1,c2);
return 0;
}