Issue with typeof

StarGrazer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Mar 21 08:09:00 PDT 2017


On Tuesday, 21 March 2017 at 15:01:43 UTC, ag0aep6g wrote:
> On 03/20/2017 05:55 PM, StarGrazer wrote:
>> typeof(&method) fails unless method is static. Says & requires 
>> this.
>
> Works for me:
>
> ----
> class C
> {
>     void method() {}
>     typeof(&method) x;
> }
> typeof(&C.method) y;
> ----
>
> Tested with dmd 2.073.2.

Yes, but you changed it. I didn't have C. Initially this wasn't a 
problem.

>
> ----
> typeof(() { T t; return &t.method; } ()) fptr3;
> ----
>
>> e.g., `void function();` for `void foo();`
>
> Really should be `void delegate()`. With the `function` type 
> you're losing the `this` pointer.

You are making assumptions... my functions where static and I was 
trying to convert them to non-static methods and this is where 
the trouble started creeping in.



More information about the Digitalmars-d-learn mailing list