overloading operators in object pascal? 
Author Message
 overloading operators in object pascal?

Anyone know how to overload operators in delphi (object Pascal)?

I know how to do so in C++, but I can't seem to find anything about it in
the on-line manuals for Delphi (object pascal).

Please e-mail me as well as post.

----------------------------------------------------------------------
| Jerry & Ellen Davis  | If work were like my hobbies, then I would  |
|                      | want to WORK all the time!                  |
----------------------------------------------------------------------



Wed, 18 Jun 1902 08:00:00 GMT  
 overloading operators in object pascal?
Anyone know how to overload operators in Delphi (object pascal)?

I know how to do so in C++, but I can't seem to find anything about it in
the on-line manuals for Delphi (object pascal).

Please e-mail me as well as post.

----------------------------------------------------------------------
| Jerry & Ellen Davis  | If work were like my hobbies, then I would  |
|                      | want to WORK all the time!                  |
----------------------------------------------------------------------



Wed, 18 Jun 1902 08:00:00 GMT  
 overloading operators in object pascal?

Quote:
> Anyone know how to overload operators in Delphi (object pascal)?

> I know how to do so in C++, but I can't seem to find anything about it in
> the on-line manuals for Delphi (object pascal).

> Please e-mail me as well as post.

No can do.  This is unfortunate.  In most cases (whenever the programmer
is using overloading in a reasonable manner), this is a disadvantage, but
on occasion it makes programming simpler and makes the program easier to
understand.


Wed, 18 Jun 1902 08:00:00 GMT  
 overloading operators in object pascal?


Quote:

> > Anyone know how to overload operators in Delphi (object pascal)?

> > I know how to do so in C++, but I can't seem to find anything about it in
> > the on-line manuals for Delphi (object pascal).

> > Please e-mail me as well as post.

> No can do.  This is unfortunate.  In most cases (whenever the programmer
> is using overloading in a reasonable manner), this is a disadvantage, but
> on occasion it makes programming simpler and makes the program easier to
> understand.

*sob* could someone please explain what 'operator overloading' is, please.
That and a couple of other phrases which I can't remember which pop up
whenever people talk about (C++?).

--
Tom Wheeley, <holyhorns>
Oh, did I mention that I went to see Bottom Live last Thursday :-))
* TQ 1.0 * Stolen Sigs!
"A common mistake that people make when trying to design something completely
foolproof is to underestimate the ingenuity of complete fools."
         -- Douglas Adams



Wed, 18 Jun 1902 08:00:00 GMT  
 overloading operators in object pascal?


Quote:


>> No can do.  This is unfortunate.  In most cases (whenever the programmer
>> is using overloading in a reasonable manner), this is a disadvantage, but
>> on occasion it makes programming simpler and makes the program easier to
>> understand.

>*sob* could someone please explain what 'operator overloading' is, please.
>That and a couple of other phrases which I can't remember which pop up
>whenever people talk about (C++?).

What operator overloading means is that the same operator (e.g. "+",
or "div") is used for different purposes depending on the context.
Object Pascal has this.  For example, "string+string" means something
quite different from "integer+integer".

What most people mean when they say that OP doesn't have operator
overloading is that it doesn't have *user-defined* overloading of
operators.  There's no way for you to redefine the meaning of "+".
You're stuck with what's there.  In C++ you're allowed to define your
own meaning for "+" when used for specified types.

The next step up from this is user defined operators.  For example,
you might be doing vector algebra and want two kinds of multiplication
of vectors:  the dot product and the cross product.  For this you
might want to define new operators "dot" and "cross" so that you can
write

  A dot B

or

  A cross B

for clarity.  Not many languages offer this, because it brings up all
kinds of questions like whether "A dot B cross C" means "(A dot B)
cross C" or "A dot (B cross C)".  (Only the second one makes sense
here.)  This puts a big burden on the user to come up with sensible
and unambiguous rules for the parser.

In any case, most of these things can be called "syntactic sugar".
For all the examples I've given, you could write functions in Delphi
to achieve the same end.  The expressions might not look so much like
the original formulas, but they are unambiguous and easy to parse.
For example, instead of "A dot (B cross C)" I might write
"dot(A,cross(B,C))".    Instead of "A + B" I'd write "Vsum(A,B)".

I hope this helps.

Duncan Murdoch



Wed, 18 Jun 1902 08:00:00 GMT  
 overloading operators in object pascal?

Quote:




>> > Anyone know how to overload operators in Delphi (object pascal)?

>> > I know how to do so in C++, but I can't seem to find anything about it in
>> > the on-line manuals for Delphi (object pascal).

>> > Please e-mail me as well as post.

>> No can do.  This is unfortunate.  In most cases (whenever the programmer
>> is using overloading in a reasonable manner), this is a disadvantage, but
>> on occasion it makes programming simpler and makes the program easier to
>> understand.

>*sob* could someone please explain what 'operator overloading' is, please.
>That and a couple of other phrases which I can't remember which pop up
>whenever people talk about (C++?).

1.Overloading of the assignment operator for classes is possible in
Delphi - see properties.
2.Overloading slows the compile process down quite a bit.  With only
very few exceptions (s.a. complex numbers) I sure don't miss it.  I've
messed myself up too many times in C++ while debugging that even there
I'd pretty much given up on using it - and when I did I put in so
many comments that it didn't really speed up developping.
3.Overloading is (in a nutshell)
   Hijacking operators (such as +,*, etc) and re-defining them for
your own data types.  Like being able to define the regular
operators for complex numbers instead of writing PlusComplex,
TimesComplex, etc.  If done properly and with restraint, it makes
the code easier to read - though often harder to debug.

Just $0.01 worth.
Jochen

________________________________________________________________________

I post, therefore I am.



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Is operator overloading possible in Turbo Pascal ?

2. HELP needed - OVERLOADING OPERATORS????

3. Error: Operator is not overloaded?

4. Overloaded operators

5. FPC - operator overloading

6. HELP needed - OVERLOADING OPERATORS????

7. operator overloading (for complex math)

8. Function Overload in Gnu Pascal ?

9. HELP Plse: Pascal equivalent of C++ Overloading

10. logical operators in pascal, help!

11. Encrytion Components(Delphi), Object Pascal Objects(other) Available for DL

12. STL for Pascal and Object Pascal

 

 
Powered by phpBB® Forum Software