So, here it’s something I don’t like about Operator_Convert.
I have two classes, ClassA and ClassB.
ClassB is a subclass of ClassA.
Now I have to rewrap these classes into 2 new parallel classes which must have easy conversion from the old ones.
So I create NewClassA and NewClassB which is a subclass of NewClassA
I try to post some simple code to better explain:
Protected Class MyClassA
End Class
Protected Class MyClassB Inherits MyClassA
End Class
Protected Class NewMyClassA
Sub Operator_Convert(c asMyClassA)
End Sub
End Class
Protected Class NewMyClassB Inherits NewMyClassA
Sub Operator_Convert(c as MyClassB)
End Sub
End Class
Now I should have it easy to convert an instance of MyClassB into a NewMyClassB, like this:
dim oldB as new MyClassB
dim newB as NewMyClassB = oldB
however the compiler complain as this:
“There are several items with this name and it is not clear which one the call refers to”
Now, I can understand why the compiler is confused: in my code oldB is clearly a MyClassB but it’s also a MyClassA.
However I’d expect the compiler could call the most “specialized” subclass’s Operator_Convert (if we can assume a subclass is a specialization of a class).
Thought?
(Ok, I can solve it using a SharedMethod which explicitly call the right Operator_Convert, but would be more elegant just use the Operator_Convert)