Posts

Showing posts with the label pure virtual function

How to use pure virtual function in C++

 #include<iostream>    //header file using namespace std ;      // header file class shape    // creating class of name shape { protected :    // access specifier float dim ;    // protected variable of data type float of name dim is declared public :        // access specifier void getdim ()        // member function in public access specifier { cin >> dim ;        } virtual float caldata ()= 0 ;      // pure virtual function declaration };      //end of class shape  (end of class should be by the semicolon) class square : public shape    //class square derived from class shape   { public :        // access specifier float caldata ()        // function definition { return dim*dim ;      //functi...