-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15_static_data.cpp
More file actions
40 lines (37 loc) · 1.09 KB
/
Copy path15_static_data.cpp
File metadata and controls
40 lines (37 loc) · 1.09 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
//example on static data member
//they are attributes of classes or class member
#include <iostream>
using namespace std;
class customer{
string name;
int number;
static int total_customer; //used static here , hame sablog ke liya same dikhna hai to ham static use kara ga
public:
customer(string name,int number)
{
this->name = name;
this->number = number;
total_customer ++; //jitna object create hoga utna ye increment hote raha ga
}
void display ()
{
cout<<name<<" "<<number<<" "<<total_customer<<endl;
}
static void display_total() //we used static member function here which directly via the class blueprint
{
cout<<"Total Customer : "<<total_customer<<endl;
}
};
int customer :: total_customer = 0;
int main()
{
customer A1("Piyush",69);
customer A2("Infy",67);
customer A3("JODI",89);
A1.display();
A2.display();
A3.display();
A2.display_total(); //method -1 via object
customer ::display_total(); //method - 2 via class name
return 0;
}