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
Write a short code using c++ to print out all odd number from 1 to 100 using a for loop
Can turbo c++ run c program?
Is c++ still in demand?
Explain public, protected, private in c++?
Write a recursive program to calculate factorial in c++.
What does the ios::ate argument do?
What is the use of endl?
What is c++ programming language?
How do you differentiate between overloading the prefix and postfix increments?
Why do we need function?
Where must the declaration of a friend function appear?
I want explanation for this assignment: how to connect mysql database using c/c++,please explain this detailly?
What are the steps in the development cycle?
What is the use of endl in c++?
What is a friend function in c++?