[fpc-pascal] Question about operator overloading and classes
Andreas Resch
thabaker at gmx.net
Sun May 17 19:11:05 CEST 2009
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi everybody,
I'm toying with operator overloading and classes.
For example I want have a class that stores a value (of some type) and
related to it additional information. For example imagine a class that
stores a value and the associated unit: value=10, unit="px", plus
whatever. Normally you have than two or more Properties which you will
set one after another. In the spirit of the example let us imagine the
property will be called "left", so left.Value := and left.Unit := have
to be called.
I also would like to read from this class. I can overload the assignment
operator := in order to convert the class to a string s:
s:=left;
and s would be '100px'.
The problem: I can't read the Value directly into an integer i by:
i:=left; // instead of i:=left.Value
.
If I try to overload the := operator a "impossible operator overload"
error is raised. Is this related to the pointer-operator-overload thing?
Better would be to declare left.Value as the default property for
integer assignments. Either way I don't see why current limitations are
useful: integer/pointer to class or default properties only on indexed
properties are in my opinion only important if the a unique decision by
type is not possible. Especially because a "to-string" assignment works
in every case. Only "ordinal" types like integer,byte, boolean,char are
blocked. I suggest to rethink it.
Andreas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
iEYEARECAAYFAkoQRSkACgkQfp5vA04Sl1aJUwCfUOrqMiAv0YTST0mHk5Eq0CdV
n5gAoIRGfDgTxxMUzZMBOa/3AcB0BVg9
=GYEf
-----END PGP SIGNATURE-----
More information about the fpc-pascal
mailing list