![]() |
AW: Maßeinheiten als Typen
Zitat:
Delphi-Quellcode:
TGewicht = record
private FValue : Extended; private const GrammPerKilo = 1000.0; GrammPerTonne = 1000.0*GrammPerKilo; GrammPerMegat = 1000.0*1000.0*GrammPerTonne; public Class Operator Implicit(const Value:TTonne):TGewicht; end; class operator TGewicht.Implicit(const Value: TTonne): TGewicht; begin Result.FValue := Value*GrammPerTonne; end; |
AW: Maßeinheiten als Typen
:gruebel:Öhmm.....jup.....nochmal getestet...nu tuts.....komisch.
Am Rande
Delphi-Quellcode:
In die IDE zeigt mir hier einen Fehler im Implementation Abschnitt an, das der Bezeichner redifiniert wird. Allerdings erst bei Implicit(const value:TKilo). Der Compiler läuft ohne Probleme durch, und lt. meinen
Type
TGramm = -xxxxxx .. xxxxxx usw. TGewicht = record //wie gehabt Class Oporator Implicit(const value:int64):TGewicht; Class Operator Implicit(const value:TGewicht):Int64; Class Operator Implicit(const value:TGramm):TGewicht; Class Operator Implicit(const value:TKilo):TGewicht; Class Operator Implicit(const value:TTonne):TGewicht; IMPLEMENTATION Class Opertator TGewicht.Implicit(const value:int64):TGewicht; begin result.fvalue := value; end; Class Opertator TGewicht.Implicit(const value:TGewicht):Int64; begin result := value.fvalue; end; Class Opertator TGewicht.Implicit(const value:TGramm):TGewicht; begin result.fvalue := value; end; Class Opertator TGewicht.Implicit(const value:TKilo):TGewicht; begin result.fvalue := value*GrammPerKilo; end; Class Opertator TGewicht.Implicit(const value:TTonne):TGewicht; begin result.fvalue := value*GrammPerTonne; end; Unittests wird das ganze auch korrekt gehandhabt. |
AW: Maßeinheiten als Typen
Delphi-Quellcode:
// <-- classname korrekt?
Class Oporator Implicit(const value:int64):TGewicht;
Delphi-Quellcode:
// <-- classname korrekt?
Class Opertator
|
AW: Maßeinheiten als Typen
@Kodezwerg
Nope, da sind nur zwei Tippfehler hier im Forum drinn, im Quelltext is alles richtig geschrieben. Außerdem würde da der Compiler auch Meckern. :) Die Fehlermeldung ist: "Bezeichner neu deklariert TGewicht.Implicit !" Auch ein overload bei der Deklaration hilft leider nicht. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:59 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz