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 the use of c++ programming language in real life?
program explaining feautures of c++
What is near, far and huge pointers? How many bytes are occupied by them?
Explain about templates of C++.
Explain the difference between class and struct in c++?
What is the syntax for a for loop?
Is it possible to have a recursive inline function in c++?
What is the header file for setw?
Why was c++ made?
Explain rethrowing exceptions with an example?
What is token c++?
What is an undefined behavior and sequence points
What is the best it certification?
Is the declaration of a class its interface or its implementation?
What is the equivalent of Pascal's Real a) unsigned int b) float c) char