-
Notifications
You must be signed in to change notification settings - Fork 0
/
static.cpp
59 lines (48 loc) · 980 Bytes
/
static.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
#include <iostream>
using namespace std;
class Algebra
{
private:
int x;
int y;
static int z;
public:
// non-statuc_member_functions
Algebra(int x = 0, int y = 0)
{
setX(x);
setY(y);
}
void setX(int x) { this->x = x; }
void setY(int y) { this->y = y; }
void setData(int x, int y)
{
setX(x);
setY(y);
}
int getX() { return x; }
int getY() { return y; }
void getData()
{
cout << "x = " << x << "\t y=" << y << "\n";
}
// static_member_functions
static void setZ(int z){Algebra::z=z;}
static int getZ(){return Algebra::z;}
~Algebra()
{
cout << "Destructor exectued:"
<< "\n";
}
};
int Algebra::z;//can be initlized to 0 by deafult
int main()
{
Algebra::setZ(100);
Algebra obj1,obj2;
obj1.setZ(200);
cout<<Algebra::getZ()<<"\n";//200
obj2.setZ(300);
cout<<obj1.getZ()<<"\n";//300
return 0;
}