Do operators work on a Point structure?

  • Thread starter Larry Serflaten
  • Start date
L

Larry Serflaten

I am trying to add 2 points together, and I am not succeeding.
It appears the docs say I need a point and a size, but even that fails
in the copy of VS 2003 I have.

Exactly what are they trying to say here?

http://msdn.microsoft.com/library/d...rfSystemDrawingPointClassop_AdditionTopic.asp

Can't I use: pt1 = pt2 + pt3

Or do I need a size: pt1 = pt2 + sz3

The only thing that compiles, is as shown:

pt1 = Point.op_Addition(pt2, sz3)

But that doesn't show in Intellisense, what's going on?

LFS
 
J

Jay B. Harlow [MVP - Outlook]

Larry,
Neither VB.NET 2002 nor VB.NET 2003 support overloaded operators. VB.NET
2005 (Whidbey) will however support using & defining overloaded operators!


So for now you will need to explicitly call the operators, as you showed.
pt1 = Point.op_Addition(pt2, sz3)

But that doesn't show in Intellisense, what's going on?
You need to turn off the "Hide advanced members" under "Tools - Options -
Text Editor - Basic - General"


Hope this helps
Jay
 
L

Larry Serflaten

Jay B. Harlow said:
Larry,
Neither VB.NET 2002 nor VB.NET 2003 support overloaded operators. VB.NET
2005 (Whidbey) will however support using & defining overloaded operators!

You would think they would say that, instead of:

" In Visual Basic, you can use the operators defined by a type, but you cannot define your own."

That is what is on the page, and it is misleading. The 'you can use' should not be on that page....

:-(
LFS
 
H

Herfried K. Wagner [MVP]

* "Larry Serflaten said:
You would think they would say that, instead of:

" In Visual Basic, you can use the operators defined by a type, but you cannot define your own."

That is what is on the page, and it is misleading. The 'you can use' should not be on that page....

Mhm... An operator is only a special procedure, and you can call this
procedure from VB.NET ;-). If a language's addition operator is not
'+', and instead it's 'ADD', then documentation will be misleading
too...
 
J

Jay B. Harlow [MVP - Outlook]

Larry,
The "you can use" means you can call the sub directly as you have found, I
agree it is misleading, as it does not support using the operator itself.

Hope this helps
Jay
 
L

Larry Serflaten

Herfried K. Wagner said:
Mhm... An operator is only a special procedure, and you can call this
procedure from VB.NET ;-).

Where do you get that?

//000048: A = 1
IL_0001: ldc.i8 0x1
IL_000a: stloc.0
//000049: B = 2
IL_000b: ldc.i8 0x2
IL_0014: stloc.1
//000050: C = A + B
IL_0015: ldloc.0
IL_0016: ldloc.1
IL_0017: add.ovf
IL_0018: stloc.2

Add.ovf is not a special procedure of any given data type.
If we were talking about a reference type, then of course, it has
to a procedure, but we're not, we are talking about a value type
so I would think any defined operators would be candidates
for inlining the code....

If a language's addition operator is not
'+', and instead it's 'ADD', then documentation will be misleading
too...


I was looking at the "Point Addition Operator" Page, that indicates
that such an operation is possible using the 'operator' as would be
expected. The text goes on to say 'you can use' regaurdless of
whatever else it says. I would (and did) suggest that it should not
use those words, that it should say something more like:

"The Point addition operator is not supported in Visual Basic."

It could also add, what you said, "To add two points together,
call the op_Addition method from your code.

How does their generic remark help the user? (its the same remark
as the other common operators) It is actually a source of
confusion when the remarks say 'you can use' but the reality
is that you cannot.

I already suggested they change the wording, so I am moving on,
no reply is necessary.... :)

LFS
 
J

Jay B. Harlow [MVP - Outlook]

Larry,
Add.ovf is not a special procedure of any given data type.
If we were talking about a reference type, then of course, it has
to a procedure, but we're not, we are talking about a value type
so I would think any defined operators would be candidates
for inlining the code....
Your leaving out one minor point. Int32 (Integer) is a "native" IL value
type, in that there are specific IL instructions for Integers. Where as
Point is simply a value type.

If you look at System.Int32 you will not find an op_Add, where as on
System.Drawing.Point, there is an op_Add.

The compiler has to treat Integer differently then it does Point (the
difference being having specific IL instructions, not whether its a value
type or a reference type). Adding support for overloading operators (the
op_Add routines) is above & beyond what is needed for the "native" IL value
& reference types. (Reference types such as Array & String). I hope you
agree if the compiler did not support the "native" IL types, you would have
an extremely limited compiler ;-)

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top