Einzelnen Beitrag anzeigen

Benutzerbild von Khabarakh
Khabarakh

Registriert seit: 18. Aug 2004
Ort: Brackenheim VS08 Pro
2.876 Beiträge
 
#5

Re: Logik von überladenen Operatoren ? - Grundsatzfrage

  Alt 15. Jun 2006, 10:17
Zitat von jfheins:
Er weis ja, dass ein TIBTime (oder so) rauskommen soll, [...]
Es soll ein String rauskommen .

Ich kann das Verhalten nur für den CSC erklären, aber wenigstens würde er im oberen Beispiel das Gleiche wie der Delphi-Compiler ausspucken. Könnte also gut sein, dass die Borländer die Überladungsauflösung bei ihrem Compiler gleich oder wenigstens ähnlich gestaltet haben.
Zitat von C# Language Reference:
7.2.4 Binary operator overload resolution
An operation of the form x op y, where op is an overloadable binary operator, x is an expression of type X, and
y is an expression of type Y, is processed as follows:
• The set of candidate user-defined operators provided by X and Y for the operation operator op(x, y) is
determined. The set consists of the union of the candidate operators provided by X and the candidate
operators provided by Y, each determined using the rules of §7.2.5. If X and Y are the same type, or if X and
Y are derived from a common base type, then shared candidate operators only occur in the combined set
once.
If the set of candidate user-defined operators is not empty, then this becomes the set of candidate operators
for the operation. Otherwise, the predefined binary operator op implementations become the set of
candidate operators for the operation.
The predefined implementations of a given operator are specified in
the description of the operator (§7.7 through §7.13).
Eigene Operatoren werden also bevorzugt, der Compiler wählt die Überladung von X=TIBZeit.

Im Zweifelsfalle also lieber eine explizite Umwandlung verwenden .
Sebastian
Moderator in der EE
  Mit Zitat antworten Zitat