-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfriend_fun1.cpp
More file actions
39 lines (39 loc) · 781 Bytes
/
friend_fun1.cpp
File metadata and controls
39 lines (39 loc) · 781 Bytes
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
#include<iostream>
using namespace std;
class stud3;
class stud1;
class stud1
{
private: int a;
public:
void set_stud1()
{
a = 10;
}
friend void stud2(stud1 ob1,stud3 ob3); ///friend function is accessing the member of class stud1
};
class stud3
{
private: int b;
public:
void set_stud3()
{
b = 20;
}
friend void stud2(stud1 ob1,stud3 ob3); ///friend function is also accesssing the member of class stud2
};
void stud2(stud1 ob1, stud3 ob3)
{
int c;
c = ob1.a+ob3.b;
cout<<c;
}
int main()
{
stud1 obj;
obj.set_stud1();
stud3 obj3;
obj3.set_stud3();
stud2(obj,obj3); //friend function has values of both the classes
return 0;
}