J
Joe HM
Hello -
The following code will crash if the TestA() instances are declared as
Private and work just fine if they are Public.
Is there a way to hide these instances to callers from outside the
Module? It should only be possible to call the one instance of TestA()
without the second argument.
ModuleX
Sub main()
initialize(0)
TestA(0)
End Sub
Public Class cProjectBase
End Class
Public Class cProjectA
Inherits cProjectBase
End Class
Public Class cProjectB
Inherits cProjectBase
End Class
Dim mProjectInstance As Object
Sub initialize(ByVal aFlag As Integer)
If aFlag = 0 Then
mProjectInstance = New cProjectA
End If
If aFlag = 1 Then
mProjectInstance = New cProjectB
End If
End Sub
Public Sub TestA(ByRef aDummy As Integer)
TestA(aDummy, mInstance)
End Sub
Private Sub TestA(ByRef aDummy As Integer, ByRef aX As cProjectA)
Console.WriteLine("TestA for cProjectA")
End Sub
Private Sub TestA(ByRef aDummy As Integer, ByRef aX As cProjectB)
Console.WriteLine("TestA for cProjectB")
End Sub
End Module
Thanks,
Joe
The following code will crash if the TestA() instances are declared as
Private and work just fine if they are Public.
Is there a way to hide these instances to callers from outside the
Module? It should only be possible to call the one instance of TestA()
without the second argument.
ModuleX
Sub main()
initialize(0)
TestA(0)
End Sub
Public Class cProjectBase
End Class
Public Class cProjectA
Inherits cProjectBase
End Class
Public Class cProjectB
Inherits cProjectBase
End Class
Dim mProjectInstance As Object
Sub initialize(ByVal aFlag As Integer)
If aFlag = 0 Then
mProjectInstance = New cProjectA
End If
If aFlag = 1 Then
mProjectInstance = New cProjectB
End If
End Sub
Public Sub TestA(ByRef aDummy As Integer)
TestA(aDummy, mInstance)
End Sub
Private Sub TestA(ByRef aDummy As Integer, ByRef aX As cProjectA)
Console.WriteLine("TestA for cProjectA")
End Sub
Private Sub TestA(ByRef aDummy As Integer, ByRef aX As cProjectB)
Console.WriteLine("TestA for cProjectB")
End Sub
End Module
Thanks,
Joe