No subject

Manu turkeyman at gmail.com
Thu Apr 18 07:41:19 PDT 2013


Can anyone explain this restriction to me?


Trying to extern to a C++ class.

// mirror the C++ vtable
extern (C++) interface IVirtuals
{
void virtualMethod();
}

// create a struct to pose as the C++ class
struct Test
{
// make the virtuals accessible with 'static this'
@property IVirtuals _vtable() { return cast(IVirtuals)&this; }
alias _vtable this;

// class members can be defined here...
}


So that's fine. But the line I'm interested in is:
alias _vtable this;

Aliasing a property like that works fine, but why doesn't this work:

alias (){ return cast(IVirtuals)&this; } this;

Or this:
alias (() => cast(IVirtuals)&this) this;

Or even:
alias (cast(IVirtuals)&this) this;

I don't really see how they're different than the property?
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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130419/96e883db/attachment-0001.html>


More information about the Digitalmars-d mailing list