Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class BCA{
- int x;
- static int count;
- public:
- // defualt constructor
- BCA(){
- count++;
- }
- static int getcount(){
- return count;
- }
- };
- int BCA::count=0;
- int main()
- {
- cout<<"Intial value of count. "<<BCA::getcount()<<endl;
- BCA a;
- cout<<"count after 1st obj. "<<BCA::getcount()<<endl;
- BCA b;
- cout<<"count after 2nd obj. "<<BCA::getcount()<<endl;
- BCA c;
- cout<<"count after 3rd obj. "<<BCA::getcount()<<endl;
- return 0;
- }
- /*
- Output
- Intial value of count. 0
- count after 1st obj. 1
- count after 2nd obj. 2
- count after 3rd obj. 3
- */
Advertisement
Add Comment
Please, Sign In to add comment