Einzelnen Beitrag anzeigen

Der schöne Günther

Registriert seit: 6. Mär 2013
6.110 Beiträge
 
Delphi 10 Seattle Enterprise
 
#10

AW: Vektorklasse mit echten Operatoren

  Alt 17. Mär 2014, 15:48
Wie sieht es eigentlich mit dem "Nextgen"-Compiler aus? Da müsste doch für Klassen mittlerweile volle Operator-Überladung funktionieren, oder?
Was bringt dich zu der Annahme?
Automatische Referenzzählung:
Delphi-Quellcode:
var
   obj1, obj2: TMyObject;
begin
   obj2 := obj1 + obj1 + obj1;
end;
Allein für die erste "Addition" entsteht ein vom Programmierer nicht referenzierbares "Zwischenobjekt". Der Programmierer kann es nicht explizit freigeben und es liegt auf Ewig unbenutzt im Speicher.

Deshalb gibt es im "alten" Delphi-Compiler keine Operator-Überladung für Klassen. Dachte ich.

Mit ARC hat man dieses Problem ja nicht.

Anscheinend habe ich sogar Recht:
Zitat:
A very interesting side effect of using ARC memory management is that the compiler can handle the lifetime of temporary objects returned by functions. One specific case is that of temporary objects returned by operators. In fact, a brand new feature of the new Delphi compiler is the ability to define operators for classes, with the same syntax and model that has been available for records since Delphi 2006.

Note: The following code example works with the Delphi mobile (iOS) compilers, but cannot be compiled by the Delphi desktop compilers.
(Quelle: Embarcadero Docwiki)


Mann, gebt mir endlich den "Nextgen"-Compiler für Windows
  Mit Zitat antworten Zitat