Jim,
| And on idea #1, the operator overload describes handling of certain
| overloaded operators, but it doesn't address how to access different
| op_Explicit
| operators that only differ by return type. There doesn't appear to be a
way
| for me to indicate to the VB compiler the return type of op_Explicit.
You are correct for VB.NET 2002 & 2003 as they simply do not support
Operator Overloading. VB.NET 2005 fully supports Operator Overloading, ergo
my suggesting option #2!
op_Explicit is an implementation detail of Overload Operators specifically
Operator CType, VB.NET 2002 & 2003 can call op_Explicit however VB.NET 2002
& 2003 cannot resolve the overloaded return types. VB.NET 2005 will see
op_Explicit as an Overload CType operator & call the correct op_Explicit for
the CType that you are attempting to do. For Example:
' VB.NET 2005 syntax
Dim anA As A
Dim aB As B
Dim aC as C
anA = CType(aC, A) ' calls op_Explicit that returns A
aB = CType(aC, B) ' calls op_Explicit that returns B
For info on overloading the CType operator see:
http://msdn2.microsoft.com/library/yf7b9sy7(en-us,vs.80).aspx
In VB.NET 2005 the op_Explicit routines would be defined something like:
Public Class C
...
Public Shared Narrowing Operator CType(ByVal aC As C) As A
' return a new A object...
End Operator
Public Shared Narrowing Operator CType(ByVal aC As C) As B
' return a new B object...
End Operator
End Class
op_Implicit defines an overloaded Widening Operator CType.
Hope this helps
Jay
| Hi Jay,
|
| thanks for the response.
|
| Unfortunately, #2 isn't an option since they're not my classes.
|
| And on idea #1, the operator overload describes handling of certain
| overloaded operators, but it doesn't address how to access different
| op_Explicit
| operators that only differ by return type. There doesn't appear to be a
way
| for me to indicate to the VB compiler the return type of op_Explicit.
|
| It doesn't appear VB handles this case. Any other ideas?
|
| Jim
|
|
|
| "Jay B. Harlow [MVP - Outlook]" wrote:
|
| > Jim,
| > I can think of two possible solutions:
| >
| > 1. Use VS.NET 2005 (aka Whidbey, currently in beta, due out later in
2005)
| > as it supports defining & consuming the conversion operators. For
details
| > see:
http://lab.msdn.microsoft.com/vs2005/
| >
| > 2. Move one or both of the conversion operators into the other classes.
| > Instead of defining both in C, consider defining one in A & one in B.
| >
| > Hope this helps
| > Jay
| >
|