getting member functions of a struct and Error: identifier expected following ., not this

thedeemon dlang at thedeemon.com
Wed Jan 24 07:55:01 UTC 2018


On Tuesday, 23 January 2018 at 00:00:38 UTC, aliak wrote:
> Hi, I'm trying to get a list of only member functions of a 
> struct. I've found that if you do not declare a struct as 
> static inside a scope, then there's a hidden "this" member as 
> part of the struct. Can someone explain the logic there?

The struct defined inside a scope can mention variables defined 
in that scope (e.g. use them in its methods), so it needs a 
pointer to the place where those closed variables live. That's 
the main difference between such struct and a static one that 
cannot use those scope vars. I guess you're seeing that pointer 
as additional member.


As for static foreach, when you write a simple foreach over some 
compile-time tuple (like in this case), it's unrolled at compile 
time similarly to "static foreach", the main difference is 
whether it creates a sub-scope for the loop body or not. 
"foreach" creates one, "static foreach" doesn't.


More information about the Digitalmars-d-learn mailing list