What are Virtual Functions? How to implement virtual
functions in "C" ?
Answer Posted / arati pradhan
A function declared with the keyword virtual, termed as
virtual function.It is used for runtime polymorphism. When
a function is declared as virtual function, the function of
that object is invoked which is refernced by the base
pointer.
Example-
class BASE
{
public:
virtual void show()
{
cout<<"withen base";
}
};
class DERIVED:public BASE
{
public:
void show()
{
cout<<"withen derived";
}
};
void main()
{
BASE *b,b1;
DERIVED d1;
b=&b1;
b->show(); //call the BASE show()
b=&d1;
b->show(); //call the DERIVED show()
getch();
}
| Is This Answer Correct ? | 9 Yes | 4 No |
Post New Answer View All Answers
What is pure virtual function? Or what is abstract class?
Can constructor be private in c++?
Is rust better than c++?
How the keyword struct is different from the keyword class in c++?
What is a dynamic binding in c++?
What are the extraction and insertion operators in c++? Explain with examples.
How can a called function determine the number of arguments that have been passed to it?
What is the difference between reference and pointer?
What is a buffer c++?
Should you pass exceptions by value or by reference?
Differentiate between late binding and early binding.
What is c++ flowchart?
What is the role of C++ shorthand's?
Are php strings immutable?
What are the comments in c++?