-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatic2.cpp
More file actions
40 lines (36 loc) · 769 Bytes
/
static2.cpp
File metadata and controls
40 lines (36 loc) · 769 Bytes
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
#include<iostream>
using namespace std;
class num
{
private:
int a; //instance variable or member variable
static int count; //Static variable
public:
void set(int x)
{
a = x;
cout << "Number : " << a << endl;
count++;
}
void display() //instance member function
{
cout << "Count = " << count << endl;
}
static void see() //static member function
{
cout << "Initial Counting = " << count << endl;
}
};
int num::count=0; //static member variable define
int main()
{
num::see(); //without creating object calling of static member variable using static member function
num n1,n2;
n1.display();
n2.display();
n1.set(5);
n1.display();
n2.set(8);
n2.display();
return 0;
}