alias this on module

Jonathan Marler via Digitalmars-d digitalmars-d at puremagic.com
Sun Apr 30 16:59:43 PDT 2017


On Sunday, 30 April 2017 at 23:44:32 UTC, Steven Schveighoffer 
wrote:
> On 4/30/17 7:35 PM, Jonathan Marler wrote:
>> Any reason why "alias this" doesn't work at the module level?  
>> If I
>> recall correctly, a module is really just a "class" under the 
>> hood, but
>> when I tried to use it I got:
>>
>> Error: alias this can only be a member of aggregate, not module
>> <module-name>
>>
>
> public import is to modules as alias this is to structs/classes 
> :)
>
> -Steve

They're actually different.

//
// File: mymodule.d
//
module mymodule;

struct Foo
{
     int bar;
     void baz();
}
__gshared Foo foo;
alias foo this; // using "alias this" on a module


//
// File: main.d
//
import mymodule;

// now the symbol "x" refers to foo.x, and the symbol "baz" 
refers to foo.baz.














More information about the Digitalmars-d mailing list