-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path28_b_Friend_Function.cpp
More file actions
61 lines (46 loc) · 973 Bytes
/
28_b_Friend_Function.cpp
File metadata and controls
61 lines (46 loc) · 973 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
50
51
52
53
54
55
56
57
58
59
60
61
// Swapping Numbers Example...!!
#include<iostream>
using namespace std;
class c2; // --> Forward Declaration...!!
class c1{
int Val1;
friend void exchange(c1 &, c2&);
public:
void intData(int a){
Val1 = a;
}
void display(void){
cout << "The value is: "<< Val1 << endl;
}
};
class c2{
int Val2;
friend void exchange(c1 &, c2&);
public:
void intData(int a){
Val2 = a;
}
void display(void){
cout << "The value is: "<< Val2 << endl;
}
};
void exchange(c1 &x, c2 &y){
int temp = x.Val1;
x.Val1 = y.Val2;
y.Val2 = temp;
}
int main()
{
c1 a;
a.intData(56);
// a.display();
c2 b;
b.intData(91);
// b.display();
exchange(a, b);
cout << "The value after exchanging becomes: " ;
a.display() ;
cout << "The value after exchanging becomes: " ;
b.display() ;
return 0;
}