If I want to have a method
void mymethod(float val) {}
and another one
void mymethod (int val) {}
then when I call mymethod (1.2)
will it correctly detect the first one is the right one to call?
If I want to have a method
void mymethod(float val) {}
and another one
void mymethod (int val) {}
then when I call mymethod (1.2)
will it correctly detect the first one is the right one to call?
mymethod(1.2)
will look for a mymethod(double d)
method since literal 1.2
for an inlined numeric value is stored in a double
by default.
You should write : mymethod(1.2F)
In this case, overloading will work and mymethod(float val)
will be called.
Overloading allows to name multiple methods with the same name but with distinct parameters. At compile time, the compiler chooses the method which matches with effective parameters.
In your case, mymethod()
method is overloaded since :
void mymethod(float val) {}
void mymethod(int val) {}