-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass13.cpp
More file actions
53 lines (46 loc) · 756 Bytes
/
Copy pathclass13.cpp
File metadata and controls
53 lines (46 loc) · 756 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
40
41
42
43
44
45
46
47
48
49
//friend function with two classes
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
class B;
class A
{
private:
int a;
public:
void setData(int x)
{
a = x;
}
friend void fun1(A,B);
};
//class B
class B
{
private:
int b;
public:
void setData(int y)
{
b = y;
}
friend void fun1( A,B); //friend function
};
//definition of friend function that is declared in class A and class B
void fun1(A a,B b)
{
cout<<" sum is "<<a.a+b.b<<endl;
}
int main(int argc, char const *argv[])
{
system("cls");
A a1;
B b1;
a1.setData(20);
b1.setData(50);
//calling friend function
fun1(a1,b1);
system("pause");
return 0;
}