I have a class with 2 constructors… One public and one private… it looks to me that signatures are different with or without the any or all of the optional parameters, but the complier complains it can’t tell them apart… They are:
Public Sub Constructor(Formula As String, GroupsFirst as Boolean = True, Charge as Integer = 0)
AND
Private Sub Constructor(Formula As String, Multiplier as integer, GroupsFirst as Boolean = True, Charge as Integer = 0, IsAdduct as Boolean = False)
What am I missing? Why can’t the compiler tell these apart?
Class Class1
Public Sub Constructor(Formula As String, GroupsFirst as Boolean = True, Charge as Integer = 0)
End Sub
Private Sub Constructor(Formula As String, Multiplier as integer, GroupsFirst as Boolean = True, Charge as Integer = 0, IsAdduct as Boolean = False)
End Sub
then in Window1.Open I have
Dim c1 As New Class1("")
Dim c2 As New class1("", False)
Dim c3 As New class1("", False,0)
I found the error… I messed up the parameters passed in the new statements… I wish the complier error was clearer and just said something like “parameters do not match any method signature” , which was what it was…
Apparently if there are overloaded methods (with optional parameters?) and no signature matches the passed parameters, it just says it can’t tell which one it should use… rather than saying none match.
Dave,
I create temporary objects only for use inside the class… and for those it makes makes sense to pass additional parameters I don’t want exposed and it has slightly different initialization code (some things are skipped), hence the private constructor.
There are other ways to do that … but this way seemed simpler (and would have been if the complier error had been clearer!)