-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtut9.cpp
43 lines (35 loc) · 799 Bytes
/
tut9.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
#include <iostream>
using namespace std;
class Employee
{
int id;
// static data member , one variable can be shared for umang, vidur and deepak;
static int count; // static help to hold the value because it takes only one memory
public:
void setData(void)
{
cin >> id;
count++;
}
void getData(void)
{
cout << count << endl;
}
static void getCount(void){
// cout << id; // cannot access id because it is not static;
cout << count;
}
};
int Employee ::count;
int main()
{
Employee umang, vidur, deepak;
umang.setData();
umang.getData();
Employee::getCount(); // how to call static function
vidur.setData();
vidur.getData();
deepak.setData();
deepak.getData();
return 0;
}