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 runtime errors c++?
Evaulate: 22%5 a) 2 b) 4 c) 0
Why is c++ is better than c?
Describe the role of the c++ in the tradeoff of safety vs. Usability?
Can the creation of operator** is allowed to perform the to-the-power-of operations?
Write a Program for dynamically intialize a 2 dimentional array. Eg:5x20, accept strings and check for vowels and display the no.finally free the space allocated .
Describe public access specifiers?
Is it possible to use a new for the reallocation of pointers ?
Can you declare an array without a size in c++?
Differentiate between a constructor and a method in C++.
If you hear the cpu fan is running and the monitor power is still on, but you did not see anything show up in the monitor screen. What would you do to find out what is going wrong?
What is the use of endl in c++?
What are enumerations?
What is the use of 'this' pointer?
How java is different from c and c++?