Skip to content

Instantly share code, notes, and snippets.

@ravikiran0606
Last active July 30, 2016 17:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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