<p>I was under the impression that alias this just was shorthand for<br>
Class Foo {<br>
int x;<br>
alias x this;<br>
}<br>
Foo foo = new Foo<br>
foo = 9; // foo.x = 9<br>
Foo Foo = 9 // null.x =9;<br></p>
<p>Also, for opCast, doesnt that only work for going from Foo to int and not the other way around? </p>
<p>-Mike </p>
<div class="gmail_quote">On Oct 18, 2010 3:55 PM, "Steven Schveighoffer" <<a href="mailto:schveiguy@yahoo.com">schveiguy@yahoo.com</a>> wrote:<br type="attribution">> On Mon, 18 Oct 2010 15:47:40 -0400, Mike Chaten <<a href="mailto:mchaten@gmail.com">mchaten@gmail.com</a>> wrote:<br>
> <br>>> In C++ it is possible to declare a class as follows<br>>> class Foo {<br>>> Foo(int x) { }<br>>> }<br>>> You can then use that constructor to implicitly convert int to Foo. E.g<br>
>> Foo x = 0; //equivalent to Foo(0)<br>>><br>>> Is there a way in D to do an implicit or explicit conversion from an<br>>> integral type to a class?<br>> <br>> explicit cast == opCast<br>> implicit cast == alias this<br>
> <br>> Look up those two features in the docs.<br>> <br>> -Steve<br></div>