-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatic.cpp
More file actions
69 lines (54 loc) · 1.19 KB
/
static.cpp
File metadata and controls
69 lines (54 loc) · 1.19 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
67
68
69
#include<iostream>
using namespace std;
/*
int staticNumber(){
static int x;
x++;
return x;
}
*/
class staticNumbers{
static int number;
int A;
public:
// static float number;
void changeNumber(){
number++;
}
void setNumber(){
A = ++number;
}
void getA(){
cout<<"A : "<<A<<endl;
}
static void getNumber(){
cout<<"Number : "<<number<<endl;
}
};
// float staticNumbers::number {7.007};
int staticNumbers::number {2};
int main()
{
// Static Number
/*
cout<<staticNumber()<<endl;
cout<<staticNumber()<<endl;
*/
// Static Class Variable
/*
staticNumbers x1;
staticNumbers x2;
x1.number++;
cout<<"1st Object : "<<x1.number<<"\n";
cout<<"2nd Object : "<<x2.number;
*/
// Static Class Method
staticNumbers x1, x2;
x1.setNumber();
x2.setNumber();
x1.setNumber();
x1.getA();
x2.getA();
staticNumbers::getNumber();
return 0;
}