+ 1

Overload

Why we must overload a function instead of make another one?

20th May 2018, 1:15 PM
Laur
1 Answer
+ 1
It isn't a must. But it is useful. Think it like this- You want to make a function to add two numbers. If you take two int values as input you make a program named int add(int x, int y) and when you need to add floats you need another one. Making another one with different name can be confusing or time consuming in some cases so you make another one with same name but different parameters. Also when you make a function overload the compiler is smart enough understand which function are you calling by looking(not really) at the arguments passed in. And you don't have to worry about which function is being called. Hope this helps.😂
20th May 2018, 1:27 PM
Akib
Akib - avatar