Sunday, September 25, 2016

Static Members Both Data And Function

Tags

Program To Illustrate The Concept Of Static Members :


#include<iostream>
using namespace std;
class datatype
{
    int a;
    static int count;
    public:
        datatype()
        {
            a=++count;
        }
        void show()
        {
            cout<<"\nValue of Variable is "<<a;
        }
        static void showcount()
        {
            cout<<"\nNo of Objects cretaed "<<count;
        }
};
int datatype::count;

main()
{
    datatype a,b,c;
    a.show();
    b.show();
    c.show();
    datatype::showcount();
}