Skip to content

Instantly share code, notes, and snippets.

@ravikiran0606
Last active July 30, 2016 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravikiran0606/994e58f3abe7b5abae1db30cc94a6cf4 to your computer and use it in GitHub Desktop.
Save ravikiran0606/994e58f3abe7b5abae1db30cc94a6cf4 to your computer and use it in GitHub Desktop.
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