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
Explain how to initialize a const data member.
Is map ordered c++?
Does c++ cost money?
How a pointer differs from a reference?
what is the difference between linear list linked representaion and linked representation? what is the purpose of representing the linear list in linked represention ? is it not avoiding rules of linear represention?
What is cout flush?
Explain the term memory alignment?
What is the history of c++?
Do inline functions improve performance?
If dog is a friend of boy, and terrier derives from dog, is terrier a friend of boy?
What is a float in c++?
What is public, protected, private in c++?
What is singleton pattern in c++?
What is difference between malloc()/free() and new/delete?
Can non graphic characters be used and processed in C++?