+ 2

What does overloading in c++ means?

14th Jan 2017, 4:39 PM
shubham singh
shubham singh - avatar
2 Answers
+ 5
OVERLOADING is when you create a function that works with different types and count of parameters For example, if you have function `sum`, to add support of different types like: int, float, or even string you have to OVERLOAD your function Example: int sum(int a, int b) { return a + b; } This function will take only integer values, but if you want to sum float also you should add overload of function. Example: float sum(float a, float b) { return a + b; } Now your function is returning float value when you passing `floats` to it Compiler will choose function, depending on types. From now, ehen you will call function with int parameters: sum(3, 5); It will return INTEGER value 8 Otherwise, if you will pass float values it will choose correct function, that takes floats: sum(3.5, 4.5); This code will return FLOAT value ~8.0 If it cant found function that takes given amount of arguments and have right types, it will throw an error
14th Jan 2017, 4:56 PM
WittyBit
WittyBit - avatar
+ 1
when U use the same function more than one time with diffrent parameters
4th May 2018, 4:54 PM
Ù†ÙŠŰ±Ù…ÙŠÙ† ŰąÙ„ Ű­Ù…ŰŻ
Ù†ÙŠŰ±Ù…ÙŠÙ† ŰąÙ„ Ű­Ù…ŰŻ - avatar