4/22/2017

Pure Virtual Function,Abstract Class

 

--------------------------------------

Pure virtual ==> no definition in class 

Class A{

public :

int x ;

void SetData(int a)=0 ; ///Pure virtual function

}

We can not create object of class A.

A objA; //error

All classes which have at least 1 pure virtual function is called Abstract Class

These classes object can not be created.

These classes need to be derived and pure virtual function need to be redefined.

Class D : public B{

void SetData(int a){           //redefine pure virtual function in derived class

x= a ;

///other stufff

}

D objD ; //valid and Ok

No comments:

Post a Comment