-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFriendFunctions.cpp
66 lines (46 loc) · 907 Bytes
/
FriendFunctions.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
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
class B;
class A {
private:
int val;
public:
A(){
}
A(int v){
val = v;
}
A doubleValue (){
A x(val*2);
return x;
}
friend void printVal(A x, B y);
};
class B {
private :
int name;
public:
B(){
}
B(int v){
name= v;
}
friend A A::doubleValue();
friend void printVal(A x, B y);
// To make all the functions of the class A as the friend functions of class B
friend class A;
};
void printVal(A x, B y){
cout << x.val << " " << y.name << endl;
}
int main(){
A obj1(10);
B obj2(20);
printVal(obj1, obj2);
obj1.doubleValue();
printVal(obj1, obj2);
obj1.doubleValue();
return 0;
}