-
Notifications
You must be signed in to change notification settings - Fork 1
/
Session11.cpp
64 lines (46 loc) · 966 Bytes
/
Session11.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
#include<iostream>
#include<string>
using namespace std;
// Class having a Friend Function
class Point{
// Attributes
int x, y;
public:
Point(){
x = 10;
y = 20;
}
// Write Operation
void setPoint(int x, int y){
this->x = x;
this->y = y;
}
// Read Operation
void showPoint(){
cout<<"Point is: "<<x<<":"<<y<<endl<<"\n";
}
// Firend Function is not property of Object
friend void show(Point p);
};
// This is just a regular function
void show(Point p){
// We are trying to access private data pf Point Object !!
// i.e. Outside the Class which is not possible !!
cout<<"Point in show"<<endl;
cout<<p.x<<" : "<<p.y<<endl;
}
int main(){
// Static Object Construction
// Stack
Point p1;
//cout<<p1.x<<" : "<<p1.y<<"endl"; // error -> Data Hiding
// Dynamic Object Construction
// Heap
Point* ptr = new Point();
p1.setPoint(100, 200);
ptr->setPoint(111, 222);
p1.showPoint();
ptr->showPoint();
show(p1);
return 0;
}