0
Does function overloading help in speedy execution?
Hi I am aware that function overloading helps in easy maintenance and code readability. Does it help in saving of memory space and fast execution? This site (https://www.edureka.co/blog/function-overloading-in-cpp/#advantages) claims so. If yes, please share your views on how it help in memory space and fast execution?
4 Respostas
+ 2
Another example is std::distance().
It's overloaded and thus has versions taking either a forward_iterator tag or a random_access iterator tag.
A container like vector will perform optimally when called with a version of distance having a random_iterator_tag argument as opposed to the other one
0
True that template function may save space (as it will not generate code if data type is not used in function call) but this is not digestible in terms of overloaded function...
And I don't get your point of overloaded function allowing special algorithm to run faster... Could you please elaborate or share some link for same ?
0
Thanks Robin and Anthony Maina ... Still I am confused on this.... Correct me if I have misinterpreted...
There is two functions say doSomething which takes one argument int and string making them overload...
doSomething (5) would obviously call int version and linking would happen at compile time... There is no vtable involve in overloading... Same way , doSomething ("Hi") will call string version..
Now instead of overloaded, suppose I have doSomethingInt and doSomethingString and calling respective function for 5 and "Hi" ; will this be slower compared to overloaded one ? If yes, how because all of the four function call are bind at compile time.... It's function which we have defined (all two or one overloaded) should be effectively implementated and if so, we don't have to bother whether it's overloaded or not
0
Makes sense... Thank you 😊