Error: 'this' is only defined in non-static member functions, not main

remi thebault via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jul 29 15:46:34 PDT 2015


On Wednesday, 29 July 2015 at 22:12:38 UTC, anonymous wrote:
> Slapping `static` on `get` seems to make it work:
> ----
>     static size_t get() {return member.offsetof;}
> ----

Good slap, thanks!
you solved my problem

>
> I guess the compiler thinks that since `item.link` is an 
> instance member, it needs a `this`. And then `get` would need a 
> `this` too as it's using `item.link` via `member`. When the 
> compiler sees that there is no `this`, it errors out.
>
> An explicit `static` forces the compiler to assume no `this`. 
> And it would error out if you actually tried to make use of it.
>
> Naively, I'd think the compiler should be able to figure that 
> out itself.

I guess that is a dmd bug. I'll fill a report in case of.


More information about the Digitalmars-d-learn mailing list