Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
January 13, 2021 Why doesn't this work when the function is a static method? | ||||
---|---|---|---|---|
| ||||
works fine (this is defined at global scope, g and baa are same as static) int f(HWND hwnd, int n) { return n*10; } void baa() { HWND foo; writeln(foo.f(10)); } but if I wrap this within a class: class Foo { static int f(HWND hwnd, int n) { return n*10; } static void baa() { HWND foo; writeln(foo.f(10)); } } I get the error: Error: no property f for type void* |
January 13, 2021 Re: Why doesn't this work when the function is a static method? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jack | On Wednesday, 13 January 2021 at 17:14:04 UTC, Jack wrote:
> but if I wrap this within a class:
>
> class Foo
> {
> static int f(HWND hwnd, int n)
> {
> return n*10;
> }
>
>
> static void baa()
> {
> HWND foo;
> writeln(foo.f(10));
> }
> }
>
> I get the error:
>
> Error: no property f for type void*
Member functions (including static ones) can't be called with UFCS.
|
January 14, 2021 Re: Why doesn't this work when the function is a static method? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | On Wednesday, 13 January 2021 at 17:21:23 UTC, Paul Backus wrote:
> On Wednesday, 13 January 2021 at 17:14:04 UTC, Jack wrote:
>> but if I wrap this within a class:
>>
>> class Foo
>> {
>> static int f(HWND hwnd, int n)
>> {
>> return n*10;
>> }
>>
>>
>> static void baa()
>> {
>> HWND foo;
>> writeln(foo.f(10));
>> }
>> }
>>
>> I get the error:
>>
>> Error: no property f for type void*
>
> Member functions (including static ones) can't be called with UFCS.
Thanks
is this documented somewhere? Is this going to change?
|
January 14, 2021 Re: Why doesn't this work when the function is a static method? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jack | On Thursday, 14 January 2021 at 05:44:43 UTC, Jack wrote: > On Wednesday, 13 January 2021 at 17:21:23 UTC, Paul Backus wrote: >> >> Member functions (including static ones) can't be called with UFCS. > is this documented somewhere? Is this going to change? It will stay as is. It is somewhat vaguely described in p.7 under UFCS section in functions https://dlang.org/spec/function.html#pseudo-member |
January 14, 2021 Re: Why doesn't this work when the function is a static method? | ||||
---|---|---|---|---|
| ||||
Posted in reply to evilrat | On Thursday, 14 January 2021 at 09:13:27 UTC, evilrat wrote:
> On Thursday, 14 January 2021 at 05:44:43 UTC, Jack wrote:
>> On Wednesday, 13 January 2021 at 17:21:23 UTC, Paul Backus wrote:
>>>
>>> Member functions (including static ones) can't be called with UFCS.
>
>> is this documented somewhere? Is this going to change?
>
> It will stay as is.
> It is somewhat vaguely described in p.7 under UFCS section in functions
>
> https://dlang.org/spec/function.html#pseudo-member
I see, thanks
|
January 14, 2021 Re: Why doesn't this work when the function is a static method? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jack | On Thursday, 14 January 2021 at 15:20:54 UTC, Jack wrote: > On Thursday, 14 January 2021 at 09:13:27 UTC, evilrat wrote: >> On Thursday, 14 January 2021 at 05:44:43 UTC, Jack wrote: >>> On Wednesday, 13 January 2021 at 17:21:23 UTC, Paul Backus wrote: >>>> >>>> Member functions (including static ones) can't be called with UFCS. >> >>> is this documented somewhere? Is this going to change? >> >> It will stay as is. >> It is somewhat vaguely described in p.7 under UFCS section in functions >> >> https://dlang.org/spec/function.html#pseudo-member > > I see, thanks If it's really important you can make a module-level alias to the static method. https://run.dlang.io/is/4IFsjr |
Copyright © 1999-2021 by the D Language Foundation