Due to a new functionality we need another instance constructor in a class called C_Geo_Data
.
This class contains a constructor as following:
Public Sub New(_coord_Y As Double, _coord_X As Double, ByVal _srid As Integer)
'...
End Sub
Now we need to add another constructor with following parameters:
Public Sub New(_coord_Y As Double, _coord_X As Double, ByVal _coord_Z As Double)
'...
End Sub
Note the difference in data type for the third parameter. Now there is already a function in the class calling this constructor and for the third parameter a string
is handed over to the constructor. Of course the compiler doesn't know which constructor to use and gives a compile error as following:
Overload resolution failed because no accessible 'New' can be called without a narrowing conversion:
'Public Sub New(_coord_Y As Double, _coord_X As Double, _coord_Z As Double)': Argument matching parameter '_coord_Z' narrows from 'String' to 'Double'.
'Public Sub New(_coord_Y As Double, _coord_X As Double, _srid As Integer)': Argument matching parameter '_srid' narrows from 'String' to 'Integer'.
I fixed the error by explicitly converting the string to an integer (CInt(string)
) but i wondered if there is any way to tell the caller which constructor to use without converting the parameter beforehand:
maybe something like this:
Dim test As String ="4326"
New GeoPoint(y,x,_srid=test)