<div dir="ltr">On Mon, Sep 1, 2008 at 9:11 AM, Giles Bathgate <span dir="ltr">&lt;<a href="mailto:gilesbathgate@gmail.com">gilesbathgate@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I am trying to translate the following C# code into D<br>
<br>
 &nbsp; &nbsp; public class Test<br>
 &nbsp; &nbsp; &nbsp; &nbsp;{<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;public string Name;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;public static Test operator +(Test lvalue, Test rvalue)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (lvalue == null) { lvalue = new Test(); lvalue.Name = &quot;foo&quot;; }<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (rvalue == null) { rvalue = new Test(); rvalue.Name = &quot;bar&quot;; }<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Console.Write(lvalue.Name);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Console.Write(rvalue.Name);<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return rvalue;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
<br>
void main()<br>
{<br>
 &nbsp; &nbsp;Test T = null;<br>
 &nbsp; &nbsp;Test B = null;<br>
 &nbsp; &nbsp;T += B;<br>
}<br>
<br>
Whilst leaving the syntax of main() untouched.<br>
<br>
</blockquote></div><br>Long story short: I really don&#39;t think you can.&nbsp; Operator overloading in D can only be performed as nonstatic methods of user-defined types.&nbsp; Since a virtual method call requires that the object you&#39;re calling it on be non-null (so that you can get the vtable), you can&#39;t use overloaded operators on null references.<br>
</div>