Pure virtual function - Definition - Polymorphism and Abstract Classes

Q.  A virtual function that has no definition within the base class is called____________.
- Published on 19 Oct 15

a. Pure virtual function
b. Pure static function
c. Pure Const function
d. Friend function

ANSWER: Pure virtual function
 

    Discussion

  • Brijesh   -Posted on 05 Oct 15
    A virtual function that has no definition within the base class is called as pure virtual function. If there is a condition that derived class must override the particular function or complete definition of a function is not defined in the base class then we will declare function as a virtual function in the base class.
    Syntax for declaring a pure virtual function is as follows:
    virtual ret_type fun_name(parameter_list)=0;
    Example:
    class baseClass
    {
    public:
    virtual void show()=0; //------? Pure virtual function.
    };
    class deriveClass: public baseClass
    {
    public:
    void show()
    {
    cout<<"Welcome at careeride.com";
    }
    };
    int main() {

    deriveClass obj;
    obj.show();

    return 0;
    }

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)