Make `& Class.foo` illegal

Boris Carvajal boris2.9 at gmail.com
Thu Aug 27 21:25:24 UTC 2020


On Thursday, 27 August 2020 at 11:20:17 UTC, Johan wrote:
> Currently this code is not rejected by the compiler and instead 
> creates non-functioning (undefined) code:
> struct S {
>     void foo() {}
> }
>
> void main() {
>     auto a = &S.foo;
> }

Currently, you need an instance to get a delegate, the context 
can be modified later to point to the desired instance:

auto dg = &S.init.foo;    // '&S().foo' or for classes: '&(new 
S()).foo'
S s;
dg.ptr = &s;
dg();


More information about the Digitalmars-d mailing list