ref on hidden this param

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Sun Oct 5 05:35:24 UTC 2025


On 05/10/2025 6:28 PM, TwoOfCups wrote:
> I am guessing I'm not the first person to think of this.
> 
> But allowing ref to be applied to the hidden this on member functions 
> would be nice.
> could be used for lazy init of objects, reassigning the lvalue and stuff.
> 
> Seem like a very easy thing technically so idk if there is some 
> ideological reason not to?
> 
> right now we can do
> ```
> class C{}
> void foo(ref C c){...}
> C c;
> c.foo();
> 
> ```
> 
> Which is pretty good, but an un-attached floating function can often get 
> lost from the type they are meant to be attached to during certain 
> import scenarios or certain template  scenarios so its actually not a 
> robust solution.

This cannot work.

Methods are stored in the vtable which is accessed from the this pointer.

You would be jumping to a function pointer which is acquired after a 
null dereference.



More information about the Digitalmars-d mailing list