Wednesday, June 8, 2011

Pure virtual function

#include<iostream.h>
#include<conio.h>
class xyz
{
    protected:
        int a;
        public:
        xyz(){a=10;}
        virtual void display()=0;
};

class abc:public xyz
{
        int b;
        public:
        abc(){b=20;}
        void display()
        {
                cout<<"a="<<a<<"\n"<<"b="<<b;
        }
};

int main()
{
        clrscr();
        xyz *k;                  //no object is created
        abc s;
        //k->display();          //abnormal program termination
        k=&s;
        k->display();
        return 0;
}

No comments: