I’ve some problems with the concepts of Operator Overloading, especially for the assignment.
I need objects, which represents coordinates in my system. For a 2D-case my class would have params Integer x and Integer y.
Now, I want to use the operator overloading, to have a nice coord1 + corrd2 = coord3. This works very nice for arithmetic operators.
But one big problem arises, when passing these coordinates around. For example following code:
Dim new_coord As Coordinate(1,2) // initializes new_coord.x=1, and .y=2 Dim old_coord As Coordinate = new_coord // now, old_coord.x=1 and .y=2 new_coord.x = 3 // oups, now old_coord.x is also 3
For this it would be nice, to have some copy-constructor (Yeah, I’ve learned, not to use foreign features to Xojo, but… )
So is it possible to have something like
Sub Coordinate.Operator_Convert(Assigns l_coord As Coordinate) // copying the values byval
or is it still possible to use the Operator_Convert between two identical types and I wrote some misbehaviour? :
Sub Coordinate.Operator_Convert(l_coord As Coordinate) // copying the values byval //or Sub Coordinate.Operator_Convert() Coordinate
(When Debuggin, Xojo simply ignores the last both lines)
I know that the stupiest solution would be to introduce a Coordinate.set function, where I can do this by hand, but the Assignment-Operator would be very nice to have.
Thanks you a lot!