-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatic.cpp
More file actions
44 lines (40 loc) · 1.13 KB
/
Copy pathStatic.cpp
File metadata and controls
44 lines (40 loc) · 1.13 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
41
42
43
44
//Static variables, Static Member variables and Static Member function.
#include <iostream>
using namespace std;
class KiteFunction
{
private:
int NumberOfKites; //Instance variable or Member variable
static int charkha; //Static Variable
public:
void SetNumberOfKites(int n)
{
NumberOfKites = n;
cout << "No of Kites udai => " << NumberOfKites << endl;
charkha++;
}
void displayCharkhaUse() //Instant Member Function.
{
cout << "Charkha used => " << charkha << endl;
}
static void see() //Static Member function.+
{
cout << "Charkha used => " << charkha << endl;
}
};
int KiteFunction::charkha = 0;
int main()
{
KiteFunction::see(); // Without Creating object, calling of static member variable using static member function.
KiteFunction harry, roman, johan;
harry.displayCharkhaUse();
roman.displayCharkhaUse();
johan.displayCharkhaUse();
harry.SetNumberOfKites(5);
harry.displayCharkhaUse();
roman.SetNumberOfKites(10);
roman.displayCharkhaUse();
johan.SetNumberOfKites(15);
johan.displayCharkhaUse();
return 0;
}