What is Pure Virtual Function? Why and when it is used ?

Answer Posted / talha bilal

Pure Virtual Function

class Base //Abstract base class
{
public:
virtual void show() = 0; //Pure Virtual Function
};
class Derived:public Base
{
public:
void show()
{
cout << "Implementation of Virtual Function in Derived class";
}
};

int main()
{
Base obj; //Compile Time Error
Base *b;
Derived d;
b = &d;
b->show();
}

Virtual Function

class Base
{
public:
virtual void show()
{
cout << "Base class";
}
};
class Derived:public Base
{
private:
void show()
{
cout << "Derived Class";
}
};

int main()
{
Base *b; //Base class pointer
Derived d; //Derived class object
b = &d;
b->show(); //Late Binding Occurs
}

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What do you mean by function pointer?

707


Is it possible to get the source code back from binary file?

835


What are libraries in c++?

689


What is the difference between a type-specific template friend class and a general template friend class?

656


What is class and structure in c++?

644






What is class in c++ with example?

656


What is a terminating character in c++?

875


What are arithmetic operators?

633


Explain Memory Allocation in C/C++ ?

716


What flag means?

601


Explain the difference between c & c++?

681


What is the basic structure of c++ program?

660


What are move semantics?

757


what you know about c++?

759


Please explain class & object in c++?

674