Saturday, November 5, 2011

Static member function

// Static mambre fn.
//static membr fn. is a class member fn.It could only access other static data member, or static member fn.
//objects of that class can acces static mamber fn. It is accessed only by that class.
#include<iostream>
#include<conio.h>

using namespace std;

class A{
private:
int a;
static int c;
public:
void geta(){
     cout<<" Enter a no.";
     cin>>a;
     c++;
     }
void showa(){
     cout<<"a="<<a;
     }
    
static void show_count(){
cout <<" Total object created="<<c;
}
};

int A::c;

main(){
A obj1;
obj1.geta();
A obj2;
obj2.geta();
obj1.showa();
A::show_count();
getch();
return 0;
}

No comments:

Post a Comment