-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathpassingObj.cpp
More file actions
75 lines (71 loc) · 880 Bytes
/
passingObj.cpp
File metadata and controls
75 lines (71 loc) · 880 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//passsing pointer argument in member function by reference
//using 3 objects
using namespace std;
#include<iostream>
class swapvar
{
private:
int a;
public:
void get()
{
cin>>a;
}
void swap1(swapvar *o,swapvar *o1)
{
int temp;
temp=o->a;
o->a=o1->a;
o1->a=temp;
}
void display()
{
cout<<a;
}
};
int main()
{
swapvar ob,ob1,ob2;
ob.get();
ob1.get();
ob2.swap1(&ob,&ob1);
ob.display();
ob1.display();
return 0;
}
//using 2 objects
using namespace std;
#include<iostream>
class swapvar
{
private:
int a;
public:
void get()
{
cin>>a;
}
void swap1(swapvar *o1)
{
int temp;
temp=a;
a=o1->a;
o1->a=temp;
}
void display()
{
cout<<a;
}
};
int main()
{
swapvar ob,ob1;
ob.get();
ob1.get();
ob.swap1(&ob1);
//ob directly
//ob1using arrow and object
ob.display();
ob1.display();
return 0;
}