Operator overloading

  • Thread starter Thread starter Jon Cosby
  • Start date Start date
J

Jon Cosby

VB .Net does support operator overloading, doesn't it? It seems like this
should overload binary addition, but VB doesn't recognize "Operator"

Public Shared Operator +(ByVal c1 as cnum, ByVal c2 as cnum) as cnum
' End of statement expected

End Operator
 
Jon,

No VB.net in this versions does not support operator overloading, it will in
the next.

You can read for it in this newsgroup in a messagesthread from yesterday

Cor
 
* "Jon Cosby said:
VB .Net does support operator overloading, doesn't it? It seems like this
should overload binary addition, but VB doesn't recognize "Operator"

Public Shared Operator +(ByVal c1 as cnum, ByVal c2 as cnum) as cnum
' End of statement expected

End Operator

Wait for VS.NET 2004, VB.NET currently doesn't support operator
overloading.
 
There's a section titled "Operator Overloading Usage Guidelines in Visual
Basic" in the documentation. What's that referring to?

Jon
 
* "Jon Cosby said:
There's a section titled "Operator Overloading Usage Guidelines in Visual
Basic" in the documentation. What's that referring to?

Can you post the link?
 
ms-help://MS.VSCC/MS.MSDNVS/cpgenref/html/cpconoperatoroverloadingusageguide
lines.htm
 
You can actually implement operator overloading routines, but cannot use
them in VB.NET, well, you can, but not in the traditional sense. You need to
call the routines that implement operator overloading, instead of using the
actual operators.

The routines are defined as op_***

where *** is the type of operator to overload, e.g. op_Implicit etc

--
HTH,
-- Tom Spink, Über Geek

Woe be the day VBC.EXE says, "OrElse what?"

Please respond to the newsgroup,
so all can benefit
 
Tom,

* "Tom Spink said:
You can actually implement operator overloading routines, but cannot use
them in VB.NET, well, you can, but not in the traditional sense. You need to
call the routines that implement operator overloading, instead of using the
actual operators.

The routines are defined as op_***

where *** is the type of operator to overload, e.g. op_Implicit etc

That's what the article I referenced is saying.

;-)
 
Jon,
VB.NET 2002 & 2003 only supports indirectly consuming overloaded operators
by the method that Tom Spink & Herfried indicated.

As Herfried stated, you need to wait for Whidbey for VB.NET to support
creating & consuming overloaded operators.

For a preview of what it will look like see:

http://blogs.msdn.com/cambecc/archive/2003/10/20/51265.aspx

Hope this helps
Jay
 
Tom,
You can actually implement operator overloading routines,

No you can't. You can consume most operator functions defined in other
languages, but you can't define your own. Just giving it the right
name (the op_ prefix) isn't enough.



Mattias
 
Okay! Fair enough... but just out of interest... what is 'enough'?

--
HTH,
-- Tom Spink, Über Geek

Woe be the day VBC.EXE says, "OrElse what?"

Please respond to the newsgroup,
so all can benefit
 
Tom,
Naming a VB.NET method op_Addition is not enough to allow C# to use the
overloaded operator.

When C# creates its overloaded + method a special IL attribute is placed on
the op_Addition method, this IL attribute can only be placed by compilers
(not angle braces, such as serializable).

For details on how overloaded operators are implemented at the IL level see:

http://msdn.microsoft.com/msdnmag/issues/02/02/ManagedC/default.aspx

My initial tests in Whidbey show they are using the same naming convention
for matching operators, obviously operators such as Like have no C# & C++
equivalent.

Hope this helps
Jay

Tom Spink said:
Okay! Fair enough... but just out of interest... what is 'enough'?

--
HTH,
-- Tom Spink, Über Geek

Woe be the day VBC.EXE says, "OrElse what?"

Please respond to the newsgroup,
so all can benefit
 
Intriguing... Thanks :)

--
HTH,
-- Tom Spink, Über Geek

Woe be the day VBC.EXE says, "OrElse what?"

Please respond to the newsgroup,
so all can benefit
Jay B. Harlow said:
Tom,
Naming a VB.NET method op_Addition is not enough to allow C# to use the
overloaded operator.

When C# creates its overloaded + method a special IL attribute is placed on
the op_Addition method, this IL attribute can only be placed by compilers
(not angle braces, such as serializable).

For details on how overloaded operators are implemented at the IL level see:

http://msdn.microsoft.com/msdnmag/issues/02/02/ManagedC/default.aspx

My initial tests in Whidbey show they are using the same naming convention
for matching operators, obviously operators such as Like have no C# & C++
equivalent.

Hope this helps
Jay
 
Back
Top