<div>>> You can insert a cast to Object first.</div><div><br></div>doesn't seem to work.<div>I'm trying to write a generic solution but having an innocent '<span style="font-family:Menlo;color:rgb(68,68,68)">T</span><span style="font-family:Menlo;color:rgb(68,68,68)"> </span><span style="font-family:Menlo;color:rgb(68,68,68)">opCast</span><span style="font-family:Menlo;color:rgb(68,68,68)">(</span><span style="font-family:Menlo;color:rgb(68,68,68)">T</span><span style="font-family:Menlo;color:rgb(68,68,68)"> </span><span style="font-family:Menlo;color:rgb(68,68,68)">:</span><span style="font-family:Menlo;color:rgb(68,68,68)"> </span><span style="font-family:Menlo;color:rgb(0,150,149)">int</span><span style="font-family:Menlo;color:rgb(68,68,68)">)</span><span style="font-family:Menlo;color:rgb(68,68,68)">(</span><span style="font-family:Menlo;color:rgb(68,68,68)">)</span><span style="font-family:Menlo;color:rgb(68,68,68)"> </span><span style="font-family:Menlo;color:rgb(68,68,68)">{</span><span style="font-family:Menlo;color:rgb(68,68,68)"> </span><span style="font-family:Menlo;color:rgb(0,150,149)">return</span><span style="font-family:Menlo;color:rgb(68,68,68)"> </span><span style="font-family:Menlo;color:rgb(245,125,0)">1</span><span style="font-family:Menlo;color:rgb(68,68,68)">;</span><span style="font-family:Menlo;color:rgb(68,68,68)"> </span><span style="font-family:Menlo;color:rgb(68,68,68)">}' </span>breaks it, see Error below. </div>
<div>doesn't seem to work.</div><div><br></div><div>This seems to call for a compiler solution?</div><div><br></div><div> </div><div>



<font face="Menlo">
<span style="color:#009695">import</span><span style="color:#444444"> </span><span style="color:#444444">std</span><span style="color:#444444">.</span><span style="color:#444444">stdio</span><span style="color:#444444">;</span><br>

<span style="color:#009695">import</span><span style="color:#444444"> </span><span style="color:#444444">std</span><span style="color:#444444">.</span><span style="color:#444444">conv</span><span style="color:#444444">;</span><br>

<br>
<br>
<span style="color:#009695">void</span><span style="color:#444444">*</span><span style="color:#444444">AddressOf</span><span style="color:#444444">(</span><span style="color:#444444">T</span><span style="color:#444444">)</span><span style="color:#444444">(</span><span style="color:#444444">T</span><span style="color:#444444"> </span><span style="color:#444444">a</span><span style="color:#444444">)</span><span style="color:#444444"> </span><span style="color:#009695">if</span><span style="color:#444444">(</span><span style="color:#009695">is</span><span style="color:#444444">(</span><span style="color:#444444">T</span><span style="color:#444444">=</span><span style="color:#444444">=</span><span style="color:#009695">class</span><span style="color:#444444">)</span><span style="color:#444444">)</span><span style="color:#444444">{</span><br>

<span style="color:#444444">    </span><span style="color:#009695">return</span><span style="color:#444444"> </span><span style="color:#009695">cast</span><span style="color:#444444">(</span><span style="color:#009695">void</span><span style="color:#444444">*</span><span style="color:#444444">)</span><span style="color:#009695">cast</span><span style="color:#444444">(</span><span style="color:#009695">Object</span><span style="color:#444444">)</span><span style="color:#444444"> </span><span style="color:#444444">a</span><span style="color:#444444">;</span><span style="font-style:italic;color:#999988">//</span><span style="font-style:italic;color:#999988">Error</span><span style="font-style:italic;color:#999988">:</span><span style="font-style:italic;color:#999988"> </span><span style="font-style:italic;color:#999988">template</span><span style="font-style:italic;color:#999988"> </span><span style="font-style:italic;color:#999988">instance</span><span style="font-style:italic;color:#999988"> </span><span style="font-style:italic;color:#999988">opCast</span><span style="font-style:italic;color:#999988">!</span><span style="font-style:italic;color:#999988">(</span><span style="font-style:italic;color:#999988">Object</span><span style="font-style:italic;color:#999988">)</span><span style="font-style:italic;color:#999988"> </span><span style="font-style:italic;color:#999988">opCast</span><span style="font-style:italic;color:#999988">!</span><span style="font-style:italic;color:#999988">(</span><span style="font-style:italic;color:#999988">Object</span><span style="font-style:italic;color:#999988">)</span><span style="font-style:italic;color:#999988"> </span><span style="font-style:italic;color:#999988">does</span><span style="font-style:italic;color:#999988"> </span><span style="font-style:italic;color:#999988">not</span><span style="font-style:italic;color:#999988"> </span><span style="font-style:italic;color:#999988">match</span><span style="font-style:italic;color:#999988"> </span><span style="font-style:italic;color:#999988">template</span><span style="font-style:italic;color:#999988"> </span><span style="font-style:italic;color:#999988">declaration</span><span style="font-style:italic;color:#999988"> </span><span style="font-style:italic;color:#999988">opCast</span><span style="font-style:italic;color:#999988">(</span><span style="font-style:italic;color:#999988">T</span><span style="font-style:italic;color:#999988"> </span><span style="font-style:italic;color:#999988">:</span><span style="font-style:italic;color:#999988"> </span><span style="font-style:italic;color:#999988">int</span><span style="font-style:italic;color:#999988">)</span><span style="font-style:italic;color:#999988">(</span><span style="font-style:italic;color:#999988">)</span><br>

<span style="color:#444444">}</span><br>
<span style="color:#444444">T</span><span style="color:#444444">*</span><span style="color:#444444">AddressOf</span><span style="color:#444444">(</span><span style="color:#444444">T</span><span style="color:#444444">)</span><span style="color:#444444">(</span><span style="color:#009695">ref</span><span style="color:#444444"> </span><span style="color:#444444">T</span><span style="color:#444444"> </span><span style="color:#444444">a</span><span style="color:#444444">)</span><span style="color:#444444"> </span><span style="color:#009695">if</span><span style="color:#444444">(</span><span style="color:#444444">!</span><span style="color:#009695">is</span><span style="color:#444444">(</span><span style="color:#444444">T</span><span style="color:#444444">=</span><span style="color:#444444">=</span><span style="color:#009695">class</span><span style="color:#444444">)</span><span style="color:#444444">)</span><span style="color:#444444">{</span><br>

<span style="color:#444444">    </span><span style="color:#009695">return</span><span style="color:#444444"> </span><span style="color:#444444">&</span><span style="color:#444444">a</span><span style="color:#444444">;</span><br>

<span style="color:#444444">}</span><br>
<span style="color:#009695">class</span><span style="color:#444444"> </span><span style="color:#444444">A</span><span style="color:#444444">{</span><br>
<span style="color:#444444">    </span><span style="color:#009695">int</span><span style="color:#444444"> </span><span style="color:#444444">x</span><span style="color:#444444">;</span><br>
<span style="color:#444444">    </span><span style="color:#444444">T</span><span style="color:#444444"> </span><span style="color:#444444">opCast</span><span style="color:#444444">(</span><span style="color:#444444">T</span><span style="color:#444444"> </span><span style="color:#444444">:</span><span style="color:#444444"> </span><span style="color:#009695">int</span><span style="color:#444444">)</span><span style="color:#444444">(</span><span style="color:#444444">)</span><span style="color:#444444"> </span><span style="color:#444444">{</span><span style="color:#444444"> </span><span style="color:#009695">return</span><span style="color:#444444"> </span><span style="color:#f57d00">1</span><span style="color:#444444">;</span><span style="color:#444444"> </span><span style="color:#444444">}</span><br>

<span style="font-style:italic;color:#999988">//</span><span style="font-style:italic;color:#999988">    </span><span style="font-style:italic;color:#999988">int</span><span style="font-style:italic;color:#999988"> </span><span style="font-style:italic;color:#999988">opCast</span><span style="font-style:italic;color:#999988">(</span><span style="font-style:italic;color:#999988">T</span><span style="font-style:italic;color:#999988">:</span><span style="font-style:italic;color:#999988">void</span><span style="font-style:italic;color:#999988">*</span><span style="font-style:italic;color:#999988">)</span><span style="font-style:italic;color:#999988">(</span><span style="font-style:italic;color:#999988">)</span><span style="font-style:italic;color:#999988"> </span><span style="font-style:italic;color:#999988">{</span><span style="font-style:italic;color:#999988"> </span><span style="font-style:italic;color:#999988">return</span><span style="font-style:italic;color:#999988"> </span><span style="font-style:italic;color:#999988">1</span><span style="font-style:italic;color:#999988">;</span><span style="font-style:italic;color:#999988"> </span><span style="font-style:italic;color:#999988">} //won't work either</span><br>
<span style="color:#444444">}</span><br>
<span style="color:#009695">struct</span><span style="color:#444444"> </span><span style="color:#444444">B</span><span style="color:#444444">{</span><br>
<br>
<span style="color:#444444">}</span><br>
<span style="color:#009695">void</span><span style="color:#444444"> </span><span style="color:#444444">main</span><span style="color:#444444">(</span><span style="color:#444444">)</span><span style="color:#444444">{</span><br>

<span style="color:#444444">    </span><span style="color:#444444">A</span><span style="color:#444444"> </span><span style="color:#444444">a</span><span style="color:#444444">;</span><br>
<span style="color:#444444">    </span><span style="color:#444444">writeln</span><span style="color:#444444">(</span><span style="color:#444444">AddressOf</span><span style="color:#444444">(</span><span style="color:#444444">a</span><span style="color:#444444">)</span><span style="color:#444444">)</span><span style="color:#444444">;</span><br>

<span style="color:#444444">    </span><span style="color:#444444">a</span><span style="color:#444444"> </span><span style="color:#444444">=</span><span style="color:#444444"> </span><span style="color:#009695">new</span><span style="color:#444444"> </span><span style="color:#444444">A</span><span style="color:#444444">;</span><br>

<span style="color:#444444">    </span><span style="color:#444444">writeln</span><span style="color:#444444">(</span><span style="color:#444444">AddressOf</span><span style="color:#444444">(</span><span style="color:#444444">a</span><span style="color:#444444">)</span><span style="color:#444444">)</span><span style="color:#444444">;</span><br>

<br>
<span style="color:#444444">    </span><span style="color:#444444">B</span><span style="color:#444444"> </span><span style="color:#444444">b</span><span style="color:#444444">;</span><br>
<span style="color:#444444">    </span><span style="color:#444444">writeln</span><span style="color:#444444">(</span><span style="color:#444444">AddressOf</span><span style="color:#444444">(</span><span style="color:#444444">b</span><span style="color:#444444">)</span><span style="color:#444444">)</span><span style="color:#444444">;</span><br>

<span style="color:#444444">    </span><span style="color:#444444">B</span><span style="color:#444444">*</span><span style="color:#444444">b2</span><span style="color:#444444">;</span><br>
<span style="color:#444444">    </span><span style="color:#444444">writeln</span><span style="color:#444444">(</span><span style="color:#444444">AddressOf</span><span style="color:#444444">(</span><span style="color:#444444">*</span><span style="color:#444444">b2</span><span style="color:#444444">)</span><span style="color:#444444">)</span><span style="color:#444444">;</span><br>

<span style="font-style:italic;color:#999988">//</span><span style="font-style:italic;color:#999988">    </span><span style="font-style:italic;color:#999988">writeln</span><span style="font-style:italic;color:#999988">(</span><span style="font-style:italic;color:#999988">AddressOf</span><span style="font-style:italic;color:#999988">(</span><span style="font-style:italic;color:#999988">B</span><span style="font-style:italic;color:#999988">.</span><span style="font-style:italic;color:#999988">init</span><span style="font-style:italic;color:#999988">)</span><span style="font-style:italic;color:#999988">)</span><span style="font-style:italic;color:#999988">;</span><span style="font-style:italic;color:#999988"> </span><span style="font-style:italic;color:#999988">/</span><span style="font-style:italic;color:#999988">/</span><span style="font-style:italic;color:#999988">waiting</span><span style="font-style:italic;color:#999988"> </span><span style="font-style:italic;color:#999988">for</span><span style="font-style:italic;color:#999988"> </span><span style="font-style:italic;color:#999988">rvalue</span><span style="font-style:italic;color:#999988"> </span><span style="font-style:italic;color:#999988">ref</span><span style="font-style:italic;color:#999988">,</span><span style="font-style:italic;color:#999988"> </span><span style="font-style:italic;color:#999988">DIP39</span><br>

<span style="color:#444444">}</span></font> </div><div> <br><br><div class="gmail_quote">On Wed, May 15, 2013 at 11:30 AM, Steven Schveighoffer <span dir="ltr"><<a href="mailto:schveiguy@yahoo.com" target="_blank">schveiguy@yahoo.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Wed, 15 May 2013 11:08:33 -0400, Artur Skawina <<a href="mailto:art.08.09@gmail.com" target="_blank">art.08.09@gmail.com</a>> wrote:<br>

<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
On 05/15/13 13:04, Dicebot wrote:<br>
</div><div class="im"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Wednesday, 15 May 2013 at 10:31:29 UTC, David wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
"&c" is address of reference, no class instance. I don't know if there<br>
is a way to get a pointer to class instance in D but I am not aware of one.<br>
</blockquote>
<br>
A simple cast to void* should do it: cast(void*)c<br>
</blockquote></blockquote>
<br></div><div class="im">
   class C { auto opCast(T:void*)() { return null; } }<br>
<br>
So - no - a simple cast to void* won't always work, as the op can be<br>
overloaded, even if only by accident.<br>
</div></blockquote>
<br>
You can insert a cast to Object first.<br>
<br>
-Steve<br>
</blockquote></div><br></div>