-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtut22.cpp
More file actions
47 lines (42 loc) · 783 Bytes
/
tut22.cpp
File metadata and controls
47 lines (42 loc) · 783 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
#include<iostream>
using namespace std;
class c2;
class c1{
int val1;
friend void exchange(c1 & , c2 &);
public:
void intdata(int a){
val1= a;
}
void display(void){
cout<<val1 <<endl;
}
};
class c2{
int val2;
friend void exchange(c1 & , c2 &);
public:
void intdata(int a){
val2= a;
}
void display(void){
cout<<val2 <<endl;
}
};
void exchange( c1 & x , c2 & y){
int tmp= x.val1;
x.val1= y.val2;
y.val2= tmp;
}
int main(){
c1 oc1;
c2 oc2;
oc1.intdata(34);
oc2.intdata(64);
exchange(oc1, oc2);
cout<<"the value of c1 afterexchanging becomes :";
oc1.display();
cout<<"the value of c2 afterexchanging becomes :";
oc2.display();
return 0;
}