Sign in Join

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

Mailing lists / fpc-pascal / 2001-04

Operator overloading for Objects belonging to Classes

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

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

Manuel Ritto Correa

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

Reply by email