I have 4 overloaded methods in a module mUnits, all are Protected
When I try to call one of these via:
Var value As Double = s.ToDouble
If value.IsNotANumber Then
//todo message
Break
Else
Var u64 As Integer = cCol.units //vCell.baseValue is a double
vCell.baseValue = mUnits.convertUnitToBase(value, u64)
End If
Compiler tells me Error: There is more than one method with this name but does not match any of the available signatures.
I’ve seen this compiler error before when there are no methods with that name - but doesn’t appear to be the case this time. Also there are no other methods anywhere with the same name.
Actually I don’t think so. Yes they can be typed as an integer but I can happily overload multiple methods with different enumerations, so the compiler should be able to differentiate easily.
Yes, but the base type is always integer. So certainly not double, so there shouldn’t be confusion between “enum, integer” and “double, integer”. I’m saying it should be a bug as you are passing “double, integer” which should be recognises as the last of your options.
The best you can do with return is to return a variant. You would still need to cast it to the type expected in the call though. So your class assignment would have to cast to the class.
I can’t reproduce this. I added two methods to a window, one that takes a double, the other that takes an enum, and the compiler has no trouble telling the difference even if I supply an integer instead of a double.
Ah, found it I think - though the compiler message led me astray…
The enum in one of the methods should have been desktopCheckbox.visualStates rather than desktopcheckedStates.visualstates. My typo in updating to the new APIs (ugh).
So even though the method being referred to was correctly typed (ie double, integer) the compiler seemed to confuse it with a nonexistent class (desktopCheckbox.visualStates, integer)
So you are saying you can’t have the same function name (same parameters) with a different return value (including in a module) ? Or by overload do you mean, subclassing?
somehow i thought this was always possible before…
i see now, are we sure did didn’t just change somehow?
Var d As Dictionary = functionReturningClass // Return type = Dictionary
Var m As MyClass = functionReturningClass // Return type = MyClass
Both return different types and they won’t compile yeah.
Maybe there should be a notification when you have same method and do this, since you can just have as many methods as you wish doing this. but nowhere the ide tells you there is some issue (unless you build and there is one being called)
As someone who’s becoming more prone to “senior” moments, I gave up with overloading many moons ago. Instead I’ve found using more descriptive names for functions helps me a lot.
convertDesktopCheckedStatesToBase( cb as desktopCheckedStates.visualStates, u64 as integer ) as double
convertDateToBase( d as date ) as double
convertStringToBase( s as string, u64 as integer ) as double
When you use “u64” for the property name, do you mean a Uint64? Xojo’s “Integers” are signed, so this may cause problems.