Sunday, April 4, 2021

static member function (OOP) (11)

                                /*static member function

                                     ************************/

#include<iostream>

using namespace std;

class test //making the class name test

{

private: //private part of the class

int no;

static int count; //satic data member

public: // public part of the class

void setno(); //simple member function

void dispno(); //simple member function

static void dispcount(); //static member function

};

void test :: setno() //defining member function

{

no=++count;

}

void test :: dispno() //defing member function

{

cout<<"the number is :"<<no<<endl;

}

void test :: dispcount() //defing ststic the member function

{

cout<<"counter:"<<count<<endl;

}

int test :: count; //defing the static data member

int main()

{

test t1,t2; //making the two object of the class

t1.setno(); 

t2.setno();

test :: dispcount(); //method of calling the static member function

test t3; //calling the simple member function of the calss

t3.setno();

test :: dispcount(); //method of calling the static member function of the class

t1.dispno();

t2.dispno();

t3.dispno();

}

No comments:

Post a Comment