forked from codebloded/BackToBasics.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswapobj.cpp
More file actions
66 lines (56 loc) · 1.05 KB
/
swapobj.cpp
File metadata and controls
66 lines (56 loc) · 1.05 KB
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>
using namespace std;
class B;
class A
{
private:
int data_A;
public:
void setData(int value)
{
data_A=value;
}
friend int swap(A & , B &);
void display(void)
{
cout<<"The value from class A is "<<data_A<<endl;
}
};
class B
{
private:
int data_B;
public:
void setData(int value)
{
data_B = value;
}
friend int swap(A & , B &);
void display(void)
{
cout<<"The value from class B is :"<<data_B<<endl;
}
};
int swap(A &x,B &y)
{
int temp;
temp = x.data_A;
x.data_A = y.data_B;
y.data_B = temp;
return 0;
}
int main()
{
A objA;
B objB;
objA.setData(23);
objB.setData(45);
objA.display();
objB.display();
int swaped = swap(objA , objB);
cout<<"The value from class A after swapped is : ";
objA.display();
cout<<"The value from class B after swapped is : ";
objB.display();
return 0;
}