+ 29

What are uses of virtual function in c++??

need of virtual function

29th Oct 2017, 11:22 AM
Anisha
Anisha - avatar
11 Answers
+ 22
@manoj katari thank ušŸ˜ŠšŸ˜Š
13th Feb 2018, 9:37 AM
Anisha
Anisha - avatar
+ 23
Virtual functions ensure that the correct function is called for an object, regardless of the type of reference (or pointer) used for function call.They are mainly used to achieve Runtime polymorphism.Functions are declared with a virtual keyword in base class.The resolving of function call is done at Run-time.
3rd Dec 2017, 6:44 AM
Abhivarshini Maddala
Abhivarshini Maddala - avatar
+ 19
welcome back šŸ˜Š hope to see you at level 16 soon best luckšŸ‘šŸ‘
13th Feb 2018, 9:45 AM
Anisha
Anisha - avatar
+ 18
Maharashtra
13th Feb 2018, 9:46 AM
Anisha
Anisha - avatar
+ 8
For example you create a function in a base class, and you want to call that function in the base class to the derived classes, it is not possible to do that because you need to declare the function in the base class as a virtual function first, then you can call the function with the base class pointer. Hope this answer your question.
29th Oct 2017, 11:31 AM
Kurniawan Pratama
Kurniawan Pratama - avatar
+ 8
@anisha ...dude..I expect a like storm tooo
13th Feb 2018, 9:39 AM
manoj katari
manoj katari - avatar
+ 7
to rope in runtime polymorphism benefits to your source code.. hope u like the 'like storm'
13th Feb 2018, 9:36 AM
manoj katari
manoj katari - avatar
+ 7
@anisha... babe.... I came back to sololearn after 6 months...thanks for the warmth...
13th Feb 2018, 9:43 AM
manoj katari
manoj katari - avatar
+ 7
@anisha thanks mate.. btw you are from which place in India?
13th Feb 2018, 9:46 AM
manoj katari
manoj katari - avatar
+ 1
In simple language: A virtual function is used when we have to override the member function of our base class for our derived classes
9th Nov 2017, 1:46 PM
ROHIT SHARMA
ROHIT SHARMA - avatar
- 6
it saves the memory
8th Nov 2017, 4:53 PM
Prajwal Gowda
Prajwal Gowda - avatar