-
Notifications
You must be signed in to change notification settings - Fork 0
/
10_scopeResolutionOperter.cpp
72 lines (61 loc) · 1.41 KB
/
10_scopeResolutionOperter.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
71
72
/*Scope Resolution operater (::) define the scope of anything at any place .Used to access the gloabal varables with the same name ,access the class memeber functions outside the the class ,usedin namespaces and in the inheritance*/
// syntx:
// returnType className :: functionName (parameters) {}
#include <iostream>
using namespace std;
class algebra
{
private:
int x;
int y;
public:
// setters
void setX(int);
void setY(int);
void setData(int, int);
void setAlgebra(algebra);
// getters
int getX() const;
int getY() const;
void getData() const;
algebra getAlgebra() const;
// memberFunctions are here
//.........
};
// SETTERS_scope_resolutions
void algebra::setX(int x) { this->x = x; }
void algebra::setY(int y) { this->y = y; }
void algebra::setData(int x, int y)
{
this->x = x;
this->y = y;
}
void algebra::setAlgebra(algebra obj)
{
x = obj.x;
y = obj.y;
}
// GETTERS_scope_resolutions
int algebra::getX() const { return x; }
int algebra::getY() const { return y; }
void algebra::getData() const
{
cout << "The value of x = " << x << endl;
cout << "The value of y = " << y << endl;
}
algebra algebra::getAlgebra() const
{
return *this;
}
int main()
{
algebra obj1;
obj1.setData(1, 2);
obj1.getData();
algebra obj2;
obj2.setAlgebra(obj1);
obj2.getData();
obj1.getAlgebra().setX(8);
obj1.getData();
return 0;
}