Re: `static` function ... cannot access variable in frame of ...

2024-01-16 Thread Bastiaan Veelo via Digitalmars-d-learn
On Monday, 15 January 2024 at 23:06:00 UTC, Steven Schveighoffer wrote: As a workaround, you can alias the outer function in the struct: ```d struct S { alias foo = S_foo; } ``` This might be less than ideal, but at least it works. It does! And it's good enough for me. Thanks a lot! --

Re: `static` function ... cannot access variable in frame of ...

2024-01-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 15 January 2024 at 22:23:27 UTC, Bastiaan Veelo wrote: On Monday, 15 January 2024 at 18:43:43 UTC, user1234 wrote: The two calls are not equivalent. so what is passed as alias need to be static too. Thanks all. I thought a static member function just isn't able to access the

Re: `static` function ... cannot access variable in frame of ...

2024-01-15 Thread user1234 via Digitalmars-d-learn
On Monday, 15 January 2024 at 18:34:58 UTC, H. S. Teoh wrote: On Mon, Jan 15, 2024 at 06:16:44PM +, Bastiaan Veelo via Digitalmars-d-learn wrote: Hey people, I can use some help understanding why the last line produces a compile error. ```d import std.stdio; struct S { static void

Re: `static` function ... cannot access variable in frame of ...

2024-01-15 Thread Bastiaan Veelo via Digitalmars-d-learn
On Monday, 15 January 2024 at 18:43:43 UTC, user1234 wrote: The two calls are not equivalent. so what is passed as alias need to be static too. Thanks all. I thought a static member function just isn't able to access the instance of the struct, but as I understand now it is static all the

Re: `static` function ... cannot access variable in frame of ...

2024-01-15 Thread user1234 via Digitalmars-d-learn
On Monday, 15 January 2024 at 18:16:44 UTC, Bastiaan Veelo wrote: [...] It seems to me this should just work. Thanks! --Bastiaan. The two calls are not equivalent. To be equivalent you need to set `S_foo` static too, otherwise `S_Foo` is instanciated in `main` scope, proof: ```d import

Re: `static` function ... cannot access variable in frame of ...

2024-01-15 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jan 15, 2024 at 06:16:44PM +, Bastiaan Veelo via Digitalmars-d-learn wrote: > Hey people, I can use some help understanding why the last line > produces a compile error. > > ```d > import std.stdio; > > struct S > { > static void foo(alias len)() [...] The trouble is with the

Re: `static` function ... cannot access variable in frame of ...

2024-01-15 Thread Dukc via Digitalmars-d-learn
On Monday, 15 January 2024 at 18:16:44 UTC, Bastiaan Veelo wrote: Hey people, I can use some help understanding why the last line produces a compile error. ```d import std.stdio; struct S { static void foo(alias len)() { writeln(len); } } void S_foo(alias len)() {

`static` function ... cannot access variable in frame of ...

2024-01-15 Thread Bastiaan Veelo via Digitalmars-d-learn
Hey people, I can use some help understanding why the last line produces a compile error. ```d import std.stdio; struct S { static void foo(alias len)() { writeln(len); } } void S_foo(alias len)() { writeln(len); } void main() { const five = 5; S_foo!five; //