-
Notifications
You must be signed in to change notification settings - Fork 0
/
tut28b.cpp
70 lines (60 loc) · 1.13 KB
/
tut28b.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
67
68
69
70
#include <iostream>
using namespace std;
class c2; // Forward Declaration.
class c1
{
friend void exchange(c1 &o1, c2 &o2);
int val1;
public:
void setdata(int a)
{
val1 = a;
}
void displaydata(void)
{
cout << val1 << endl;
}
};
class c2
{
friend void exchange(c1 &o1, c2 &o2);
int val2;
public:
void setdata(int a)
{
val2 = a;
}
void displaydata(void)
{
cout << val2 << endl;
}
};
void exchange(c1 &o1, c2 &o2)
{
int temp = o1.val1;
o1.val1 = o2.val2;
o2.val2 = temp;
}
int main()
{
c1 oc1;
c2 oc2;
oc1.setdata(45);
oc2.setdata(84);
cout << "Before exchanging the value of oc1 with oc2 :-" << endl;
cout << "The value of oc1 is ";
oc1.displaydata();
cout << endl;
cout << "The value of oc2 is ";
oc2.displaydata();
cout << endl;
exchange(oc1, oc2);
cout << "After exchanging the value of oc1 with oc2 :-" << endl;
cout << "The value of oc1 is ";
oc1.displaydata();
cout << endl;
cout << "The value of oc2 is ";
oc2.displaydata();
cout << endl;
return 0;
}