0

Is it possible to have different types of parameters when you use an overload function ?

19th Dec 2017, 5:51 PM
marina
marina - avatar
4 Answers
+ 6
yes you can give different types of parameters to overloaded function like this example #include <iostream> // volume of a cube int volume(const int s) { return s*s*s; } // volume of a cylinder double volume(const double r, const int h) { return 3.1415926*r*r*static_cast<double>(h); } // volume of a cuboid long volume(const long l, const int b, const int h) { return l*b*h; } int main() { std::cout << volume(10); std::cout << volume(2.5, 8); std::cout << volume(100, 75, 15); return 0; }
19th Dec 2017, 6:12 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 1
why not
19th Dec 2017, 5:58 PM
᠌᠌Code X
᠌᠌Code X - avatar
0
all right, thanks a lot :)
19th Dec 2017, 6:25 PM
marina
marina - avatar
0
yes ...you can use different type of parameters or different numbers of parameters in overload function
19th Dec 2017, 6:29 PM
Gopal Kumar Das
Gopal Kumar Das - avatar