Operator overloading in VB

One of the nice things about reaching beta is that we’re now starting to get more whitepapers out there on new features, which reduces the number of things that I feel guilty about having not blogged about yet. The latest example of this is a whitepaper on Operator Overloading in Visual Basic 2005 written by Matt Gertz, the development lead for the VB compiler (my old job, for those of you keeping score). It’s a great overview of what we’re doing with overloaded operators, so check it out!

Now we just need a whitepaper on generics…

2 thoughts on “Operator overloading in VB

  1. Eric Mutta

    Hi Paul,

    Thanx for the pointer. The Express line of VS products is really cool by the way as it allows a lot of people to get their hands dirty without having the hefty MSDN subscription!

    Talking about generics…I have been a bit disappointed by the fact that I couldn’t do something as simple as defining a Point structure who’s X and Y co-ordinate could be parameterised (by some numerical type) and still work with operator overloading.

    The major problem is I can’t express the constraint "supports arithmetic operators". Is this possible? Furthermore, why can’t we do something like:

    Public Structure Point(Of T As {Integer, UInteger})

    so the user is restricted to using types Integer and UInteger as type parameters?

    1. paulvick

      Eric, these are just limitations that the CLR places on constraints. Being able to express richer constraints (i.e. "this type has to have this method/property/operator") is a desirable goal but just isn’t supported yet. Having multiple constraints across class types could be problematic: what if you constrained to two types whose members were entirely disjoint?


Leave a Reply

Your email address will not be published. Required fields are marked *