<div dir="ltr"><div style>Can anyone explain this restriction to me?</div><div style><br></div><div style><br></div><div style>Trying to extern to a C++ class.</div><div style><br></div><div style>// mirror the C++ vtable</div>
<div>extern (C++) interface IVirtuals</div><div>{</div><div><span class="" style="white-space:pre">     </span>void virtualMethod();</div><div>}</div><div><br></div><div style>// create a struct to pose as the C++ class</div>
<div>struct Test</div><div>{</div><div style><span style="white-space:pre">       // make the virtuals accessible with 'static this'</span><br></div><div><span class="" style="white-space:pre">       </span>@property IVirtuals _vtable() { return cast(IVirtuals)&this; }</div>
<div><span class="" style="white-space:pre">    </span>alias _vtable this;</div><div><br></div><div style><span style="white-space:pre">  // class members can be defined here...</span><br></div><div>}<br></div><div><br></div>
<div><br></div><div style>So that's fine. But the line I'm interested in is:</div><div style><span class="" style="white-space:pre">      </span>alias _vtable this;<br></div><div style><br></div><div style>Aliasing a property like that works fine, but why doesn't this work:</div>
<div style><br></div><div style><span class="" style="white-space:pre">       </span>alias (){ return cast(IVirtuals)&this; } this;<br></div><div style><br></div><div style>Or this:</div><div style><div><span class="" style="white-space:pre"> </span>alias (() => cast(IVirtuals)&this) this;<br>
</div><div><br></div><div style>Or even:</div><div style><span class="" style="white-space:pre">    </span>alias (cast(IVirtuals)&this) this;<br></div><div><br></div><div style>I don't really see how they're different than the property?</div>
<div style>I mean, I can see how they're an expression, and in the situation that works, I'm aliasing a symbol... but why is that a requirement? And why isn't a literal just as good as a symbol?</div></div></div>