<div dir="ltr">2016-02-29 13:16 GMT-03:00 Sven Barth <span dir="ltr"><<a href="mailto:pascaldragon@googlemail.com" target="_blank">pascaldragon@googlemail.com</a>></span>:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class=""><div class="h5"><p>Am 29.02.2016 16:13 schrieb "Mazola Winstrol" <<a href="mailto:mazofeifer@gmail.com" target="_blank">mazofeifer@gmail.com</a>>:<br>
><br>
> I have noticed that, by using generics, we can't overload arithmetic operators.<br>
><br>
> E.g.:<br>
><br>
> ...<br>
> class operator Negative(A: TNullableType<T>): T;<br>
> ...<br>
><br>
> class operator TNullableType<T>.Negative(A: TNullableType<T>): T;<br>
> begin<br>
>     Result := -1 * A;<br>
> end;<br>
> ....<br>
><br>
> wouldn't compile with the error "Operator not applicable to this operand type".<br>
><br>
> Is there any workaround to overcome this?</p>
</div></div><p>As far as I am concerned that *should* work. If it does not, then it's a bug. Please file a bug report with a simple example program.</p>
<p>Regards,<br>
Sven</p></blockquote><div>I apologize, it works. <br><br><br></div><div>There is a problem in my design. The code won't compile if i try to specialize with a type which doesn'y supports arithmetic operators e.g String types.<br><br></div><div><br>==== code ====<br><br></div><div>{$mode delphi}<br></div><div><br>  TNullableType<T> = record<br>  private<br>    FValue: T;<br>  public<br>    class operator Negative(A: TNullableType<T>): T;<br>  end;   <br><br></div><div>  TString = TNullableType<String>;<br></div><div><br>.....<br><br>class operator TNullableType<T>.Negative(A: TNullableType<T>): T;<br>begin<br>  Result := -1 * A.FValue;<br>end;  <br><br><br></div><div>=== code ====<br><br></div><div>Compilation error: "Operator is not overloaded: "ShortInt" * "AnsiString" ";<br><br><br></div><div>Is there any way to overcome this? Is there any way to tell the compiler to ignore some operators depending on the specialization type?<br><br></div><div>Regards<br></div><div><br></div></div></div></div>