Last active
July 30, 2016 17:21
-
-
Save ravikiran0606/994e58f3abe7b5abae1db30cc94a6cf4 to your computer and use it in GitHub Desktop.
C++ program to implement the use of static members in a class :
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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