-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrefresher_static.cpp
59 lines (47 loc) · 1.1 KB
/
refresher_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 "stdio.h"
class TestClass {
private:
static int amount;
int self_number;
public:
int always_one;
int counter;
static int static_counter;
TestClass(){
printf("An object has been init with ID #%i\n", ++amount);
self_number = amount;
always_one = 1;
};
void set_zero() {
printf("#%i has been set to zero\n", self_number);
counter = 0;
static_counter = 0;
};
void increment() {
printf("#%i has recieved increment\n", self_number);
counter += 1;
static_counter += 1;
};
void report(){printf("#%i state is: %i, %i, %i\n", self_number, always_one, counter, static_counter);};
};
using namespace std;
int TestClass::amount = 0;
int TestClass::static_counter;
TestClass article;
TestClass article2;
int main () {
article.increment();
article.report();
article2.report();
article.set_zero();
article.report();
article2.report();
article.increment();
article.report();
article2.report();
printf("Incrementing a static variable externally...\n");
TestClass::static_counter = TestClass::static_counter * 2;
article.report();
article2.report();
return 0;
};