0
overloading function
why below code result is error?? int printName(int a) { } float printName(int b) { } double printName(int c) { }
12 odpowiedzi
+ 11
Overloaded functions should have same name and different parameter list. Parameter lists may differ in three ways.
1. number of parameters
(int a)
(int a, int b)
2. type of parameters
(int a)
(double a)
3. order of parameters
(int a, float b)
(float a, int b)
The given functions have same parameter lists, so these are not overloaded. When you call them, it'll create conflict due to same argument list.
+ 10
that's not overloading
if you call
printName(15)
how can the compiler know which one to pick?
overloading means same name but different arguments
+ 2
You have stated return types, int, float, and double, but don't have a return statement in the function, so an error occurs. Just change them to "void," and change the parameter types to different ones, and it will run fine.
+ 2
Wait... a function with a return type specified that doesn't return anything works? OK I'm confused.
+ 2
Oh, OK.
+ 1
so why below code shows error ??!?!
#include <iostream>
using namespace std;
int printName(int a) { }
float printName(int b) { }
double printName(int c) { }
int main()
{
return 0;
}
0
could you please write code as above code and in conclusion , compile correct with no error ???
0
thank you
0
Oh , Yes ....
that was a great hint ....
0
so great
thank you for more details ...
0
Thait's it ...
thank you for your attention
0
Thank you for your reference