Why do we use virtual functions?
Answers were Sorted based on User's Feedback
Answer / uma sankar pradhan
we use virtual functions to achive dynamic binding
Dynamic binding is establishing relation between the
function call and function definition at run time
| Is This Answer Correct ? | 22 Yes | 2 No |
Answer / bijal
The virtual function can be allowed in base classes only.
The functions markd Virtual will only be overridable in
derieved classes.
If i m having a function in base class that shud come in
derieved class but i want it to have different behaviour.
This can only be acheived only if base class function is
virtual function.
| Is This Answer Correct ? | 23 Yes | 8 No |
A pure virtual member function is a member function that the
base class forces derived classes to
provide. Normally these member functions have no
implementation. Pure virtual functions are
equated to zero.
class Shape { public: virtual void draw() = 0; };
| Is This Answer Correct ? | 8 Yes | 4 No |
Answer / mona kawale
when there are two same classes in derived and base class then at the tym of running programm compiler get confuse about which function should b call first so it call derived class function automatically....but if we wrote base class function as virtual function then compiler will not get confuse.....
| Is This Answer Correct ? | 2 Yes | 0 No |
Why u change company?
How is data security provided in Object Oriented languages? ?
What do you mean by inline function?
Is html an oop?
Where is pseudocode used?
What is polymorphism in oop example?
what is an qt4 interface?
What causes polymorphism?
suppose A is a base class and B is the derved class. Both have a method foo which is defined as a virtual method in the base class. You have a pointer of classs B and you typecast it to A. Now when you call pointer->foo, which method gets called? The next part of the question is, how does the compiler know which method to call?
what is pointers
in the following, A D B G E C F Each of the seven digits from 0,1,2,3,4,5,6,7,8,9 is: a)Represented by a different letter in abov fig: b)Positioned in the fig abov so tht A*B*C,B*G*E,D*E*F are equal. wch does g represents? C
What do you mean by pure virtual functions?