does alias this work correctly?
Maxim Fomin
maxim at maxim-fomin.ru
Sun Jan 13 11:35:06 PST 2013
On Sunday, 13 January 2013 at 19:16:36 UTC, Zhenya wrote:
> Hi!
> Is it all right with it:
> struct Foo
> {
> struct Bar
> {
> void opCall()
> {
> writeln("non-static");
> }
> }
> Bar bar;
> static struct Anotherbar
> {
> static void bar()
> {
> writeln("static");
> }
> }
> alias Anotherbar this;
> }
>
> void main()
> {
> Foo f;
> f.bar();
> Foo.bar();//fils with message:type Bar is not an expression
> Foo.Bar b;
> b();//this works however
> }
> ?
According to spec http://dlang.org/class.html#AliasThis undefined
lookups are forwarded to AliasThis member. But in your case Foo
struct has bar member, so no further resolution is performed.
Rename the member and the code compiles.
Note, this seems to come from neighbor thread
http://forum.dlang.org/thread/uelmpwwckcveimpbdtdo@forum.dlang.org.
I think it is simpler to rename functions than create bunch of
structs just to be able to have eponymous non-static and static
functions.
More information about the Digitalmars-d-learn
mailing list