G
Gill Bates
Hope I'm not being a Pain In the A..
However; now I've got a similar issue for which I've seen no work
around...
Module Module1
Public Class BaseRow
Public Overridable Function Speak() As String
Return "BaseRow"
End Function
End Class
Public Class SpecializedRow
Inherits BaseRow
Public Overrides Function Speak() As String
Return "SpecializedRow"
End Function
End Class
Public Class Base1
Public Overridable Function NewRow() As BaseRow
Return New BaseRow
End Function
End Class
Public Class Derived1
Inherits Base1
Public Overrides Function NewRow() As SpecializedRow
Return New SpecializedRow
End Function
End Class
Public Sub main()
Dim b As New Base1
Dim d As New Derived1
Dim either As Base1
Console.WriteLine(b.NewRow.Speak)
Console.WriteLine(d.NewRow.Speak)
either = b
Console.WriteLine(either.NewRow.Speak)
either = d
Console.WriteLine(either.NewRow.Speak)
End Sub
End Module
The basic problem is:
Public Function NewRow() As SpecializedRow
in the derived class is being forced as Shadows.. I suppose I
understand why -- the signatures are the same; only diff is return
type (which is not part of a function sig); so Overload is not
approriate... however, the Overrides option is being totally rejected
by VB.Net (causes compile error) because:
Module1.vb(26): 'Public Overrides Function NewRow() As SpecializedRow'
cannot override 'Public Overridable Function NewRow() As BaseRow'
because they differ by their return types.
So, I'm not able to use Overloads or Overrides (also tried both
together) and is being forced to Shadows -- which is totally not what
I want. I want to be able to have a base class which will call the
approriate NewRow depending on the particular instance of the object
(Base or Derived). Maybe what I'm attempting is either:
1. not possible.
2. dumb.
3. or whatever...
Any suggestions?
Thanks
However; now I've got a similar issue for which I've seen no work
around...
Module Module1
Public Class BaseRow
Public Overridable Function Speak() As String
Return "BaseRow"
End Function
End Class
Public Class SpecializedRow
Inherits BaseRow
Public Overrides Function Speak() As String
Return "SpecializedRow"
End Function
End Class
Public Class Base1
Public Overridable Function NewRow() As BaseRow
Return New BaseRow
End Function
End Class
Public Class Derived1
Inherits Base1
Public Overrides Function NewRow() As SpecializedRow
Return New SpecializedRow
End Function
End Class
Public Sub main()
Dim b As New Base1
Dim d As New Derived1
Dim either As Base1
Console.WriteLine(b.NewRow.Speak)
Console.WriteLine(d.NewRow.Speak)
either = b
Console.WriteLine(either.NewRow.Speak)
either = d
Console.WriteLine(either.NewRow.Speak)
End Sub
End Module
The basic problem is:
Public Function NewRow() As SpecializedRow
in the derived class is being forced as Shadows.. I suppose I
understand why -- the signatures are the same; only diff is return
type (which is not part of a function sig); so Overload is not
approriate... however, the Overrides option is being totally rejected
by VB.Net (causes compile error) because:
Module1.vb(26): 'Public Overrides Function NewRow() As SpecializedRow'
cannot override 'Public Overridable Function NewRow() As BaseRow'
because they differ by their return types.
So, I'm not able to use Overloads or Overrides (also tried both
together) and is being forced to Shadows -- which is totally not what
I want. I want to be able to have a base class which will call the
approriate NewRow depending on the particular instance of the object
(Base or Derived). Maybe what I'm attempting is either:
1. not possible.
2. dumb.
3. or whatever...
Any suggestions?
Thanks