virtual functions
3 posters
virtual functions
Is virtual function same as the concept of overriding in java(we ll have a common method in the base class which will be overrided by the method in the derived clas )??what is the need for the keyword virtual???
aarthi- Posts : 12
Points : 22
Join date : 2010-02-26
Re: virtual functions
Virtual functions are required to achieve dynamic polymorphism. If derived class object is passed to a base class reference and overwritten function is called, base class function will be executed. So, to hide base class function, we go for vitual function.
Re: virtual functions
we can do overriding without using the keyword virtual itself....
aarthi- Posts : 12
Points : 22
Join date : 2010-02-26
Re: virtual functions
Virtual functions are not just meant for overriding. It is used to invoke derived class member functions using base class reference. Overriding is little different, it is used to hide the implementation of base class function. But still overwritten function can be called only by derived class reference.
Re: virtual functions
add up on his point........dynamically deciding upon which class to call -->>super class or sub class is the functionality of virtual functions.....for that u use reference pointers which refer to the instance of the class which contains the method
crack2drop- Posts : 4
Points : 4
Join date : 2010-03-03
Age : 36
Location : Chennai
Permissions in this forum:
You cannot reply to topics in this forum
|
|