static member function in c++ program declared.

//static member function

 
#include<iostream>
using namespace std;
class Employee
{
    int Id;
    static int count;
    public:
        void setData(void)
        {
            cout<<"Enter the Id  "<<endl;;   
        cin>>Id;
        count++;
        }
        void getData(void)
        {
       
  cout<<"This Id of this employee is  "<<Id<<"  and this employee number "<<count<<endl;
}
static void getcount(void){
    cout<<"The value of  count is "<<count<<endl;
}
};
int Employee :: count;//default vaalueis 0
int main()
{
    Employee harry, rohan ,lovish;
    harry.setData();   
    harry.getData();
    Employee::getcount()    ;

rohan.setData();   
rohan.getData();
Employee::getcount()    ;   
    lovish.setData();   
    lovish.getData();
       
    Employee::getcount()    ;
    
    return 0;

 

 output----



Comments

Popular posts from this blog

class with array in c++ (memory allocatin & using array in classes)

constructor with default arguments

constructor overloading in c++ programming