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
What is friend class in c++ with example?
What is the prototype of printf function?
How do I make turbo c++ full screen?
What is rvalue?
Will rust take over c++?
Am studying basic c++ programming, have been given the following assignment. Design a linear program to calculate the maximum stress a material can withstand given a force and a diameter of a circle. To find the required area pi should be defined. Have most of the program sorted out but am at a loss as to how to show the calculations required. Can anyone help?
What is virtual destructor ans explain its use?
Write a program in c++ to print the numbers from n to n2 except 5 and its multiples
What is boyce codd normal form in c++?
Explain bubble sorting.
What is the c++ programming language used for?
Is java a c++?
How can an improvement in the quality of software be done by try/catch/throw?
What is c++ & why it is used?
Will a recursive function without an end condition every quit, in practice a) Compiler-Specific (Some can convert to an infinite loop) b) No c) Yes