[fpc-pascal]Operator overloading for Objects belonging to Classes

Manuel Ritto Correa mcorrea at civil.ist.utl.pt
Wed Apr 4 17:48:21 CEST 2001


Hi

I am interested in using Operator overloading in self defined types. So
I wrote something like:


...

Type
  CTensor=Class
    t:Array[1..3,1..3] of Real;
    Constructor Init;
    Destructor Done;
    ...
  end;

...

Operator + (t1,t2:CTensor)tr:CTensor;
Var
  i,j:integer;
begin
  tr:=CTensor.Init;   //This is never destructed?
  For i:=1 to 3 do
    For j:=1 to 3 do
      tr.t[i,j]:=t1.t[i,j]+t2.t[i,j];
end;


in which CTensor is a class.
So in the main program I can write (a,b,c are instances of CTensor
class)

a:=b+c;

This works ok.
BUT I am worried about constructing

tr:=CTensor.Init

in the operator definition, but never being able to destruct it.
Anybody ?

Thanks in advance

Manuel Correa
 

-- 
 Everything should be made as simple as possible, but not 
simpler. Albert Einstein




More information about the fpc-pascal mailing list