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
When is the copy constructor called?
What is a storage class?
What is a forward referencing and when should it be used?
I was a c++ code and was asked to find out the bug in that. The bug was that he declared an object locally in a function and tried to return the pointer to that object. Since the object is local to the function, it no more exists after returning from the function. The pointer, therefore, is invalid outside.
How should runtime errors be handled in c++?
Explain what are the sizes and ranges of the basic c++ data types?
What would happen on forgetting [], while deallocating an array through new?
What are the various arithmetic operators in c++?
What are the various situations where a copy constructor is invoked?
Differentiate between a copy constructor and an overloaded assignment operator.
Is c++ built on c?
What is a syntax in c++?
Can constructor be static in c++?
Which is the best c++ compiler?
What are the general quetions are in DEna bank manager IT/System interviews?