forked from codebloded/BackToBasics.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathststicDF.cpp
More file actions
36 lines (33 loc) · 888 Bytes
/
ststicDF.cpp
File metadata and controls
36 lines (33 loc) · 888 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
#include<iostream>
using namespace std;
class math{
private:
static int x; //Static data member ,shared and access by all member functions
int id;
public:
void setData(void){
cout<<"Enter the math id "<<endl;;
cin>>id;
x++;
}
void getData(void)
{
cout<<"The id is "<<id<<" And the x is "<<x<<endl;
}
static void getx(void)
{
cout<<"The value of x is "<<x<<endl;
}
};
int math :: x; //outside declaration of static data member
int main()
{ math arrVar[4]; //array as an object
//Static member fucntion is aceesd by the class name no object is required to acsess the static member functions
for(int i=0 ; i<=4; i++)
{
arrVar[i].setData();
arrVar[i].getData();
math :: getx();
}
return 0;
}