Forum > General

operator overloading and TFPGList with objects

(1/1)

soerensen3:
I'm having issues using objects or records together with fpc List.
When I try to specialize a list it gives me an error (without source position) that the = operator for the record/object is not overloaded. So far, so good, even if I cannot find the line where it uses the = operator for my type in the body of TFPGList.

But even if I overload the operator it is still not working:
To compile just add the unit to the uses section of an empty program.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Unit Unit1;interface uses  fgl; type  { TVec2 }   TVec2 = object  end; operator = ( A, B: TVec2 ): Boolean; //declare operator before specialization type //start a new type section after operator declaration  TVec2List = specialize TFPGList < TVec2 >;  implementation operator = ( A, B: TVec2 ): Boolean;begin  Result:= True;end; end. 
It can be done with records with a modeswitch and a class operator. For objects it does not work though:
http://forum.lazarus.freepascal.org/index.php/topic,36469.msg243242.html#msg243242

Is it possible to use TFGPList with objects? (I need inheritance)

Blaazen:
See https://forum.lazarus.freepascal.org/index.php?topic=38887.0

Note that you will have to switch from object to record. Also, I don't know if the directive {$MODESWITCH ADVANCEDRECORDS} is available in 3.0.2. Maybe you should upgrade to 3.0.4 or use SVN.

soerensen3:
Thank you Blaazen!

I knew of the modeswitch (see the link in my post) but my question was if it was possible with objects as well, because I wanted inheritance.
But now I thought I might as well be using record helpers.

Oh and I use 3.0.4 already. The problem with the signature is you always forget updating it :)

Navigation

[0] Message Index

Go to full version