Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2000-10

assignment operator overloading

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Stefan Ziegenbalg

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.ptnil 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.

Stefan

Reply by email

Florian Klaempfl
to Stefan Ziegenbalg
you wrote 32 lines
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.ptnil 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.

Reply by email

Stefan Ziegenbalg
to Florian Klaempfl
Florian Klaempfl wrote 9 lines
>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.

I think this would be a powerful feature. Have you concrete plans or is it only an idea?

_______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Florian Klaempfl
to Stefan Ziegenbalg
you wrote 14 lines
Florian Klaempfl wrote: > >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. I think this would be a powerful feature. Have you concrete plans or is it only an idea?

We've discussed it internally and I think we know how to do it, but may know the problem of every software developer: time.

Reply by email

Peter Vreman
>I think this would be a powerful feature. Have you concrete plans or is >it only an idea? We've discussed it internally and I think we know how to do it, but may know the problem of every software developer: time.

It can be placed in the tasklist, i think it hasn't such high priority

Reply by email