C++ program to implement the use of static members in a class :
#include<bits/stdc++.h> | |
using namespace std; | |
class temp{ | |
static int c; | |
public: | |
temp(); | |
static void getcountsofar(); | |
}; | |
int temp::c=0; | |
temp::temp(){ | |
c++; | |
} | |
void temp::getcountsofar(){ | |
cout<<"The present no of counts is.."<<c<<endl; | |
} | |
int main() | |
{ | |
temp::getcountsofar(); | |
cout<<"Choice: 1) Create a new object 2) Exit"; | |
int ch; | |
while(1){ | |
cout<<"\nEnter your choice.."; | |
cin>>ch; | |
if(ch==1){ | |
temp obj; | |
temp::getcountsofar(); | |
} | |
else{ | |
break; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment