[fpc-devel]assignment operator overloading

Florian Klaempfl Florian.Klaempfl at gmx.de
Sun Oct 22 22:35:22 CEST 2000


At 01:47 22.10.2000, you wrote:
>Hi,
>
>i started to write an matrix unit. At the moment i am using a procedure
>for assignment:
>
>procedure ma(var a:matrix; b:matrix); { b --> a }
>
>I want to overload the assign operator, but i didnt work:
>
>Here my question: is it possible to make overloading of "assignment for
>equal types" and accessing to the destination variable possible?
>
>here is a example:
>
>type matrix=record
>       n,m  : longint;
>       pa   : ^double;
>       end;
>
>operator := ( b : matrix ) a : matrix;
>{ generates error: Impossible to overload assignment for equal types }
>begin
>if a.pt<>nil then freemem(a.pt,a.n*a.m*sozeof(double));
>{ generates warning: Function result does not seem to be set }
>a.n:=b.n; a.m:=b.m;
>getmem(a.pt,a.n*a.m*sizeof(double));
>end;
>
>Of course this would be a bad solution for a matrix unit (function
>results ...). But a different way (using an internal list of matrices
>and a counter for each list entry how often the matrix is used) makes it
>possible to write an comfortable matrix unit.

I'am still thinking about implementing ref. counted classes into the 
compiler together
wiht auto. decr. of the ref. counter of temp. classes in expressions.
This would solve the problem.






More information about the fpc-devel mailing list