Error: need this for method of type

2019-10-23 Thread Márcio Martins via Digitalmars-d-learn
method(1); } } ``` Output: test.d(15): Error: need this for method of type void(int x) This one as well: ``` import std.stdio; struct X { void method(int x) { writeln("method(int) called"); } } struct Y { void method(ref X x) { foreach (member; __

Re: Error: need this for method of type

2019-10-23 Thread Dennis via Digitalmars-d-learn
On Wednesday, 23 October 2019 at 11:40:09 UTC, Márcio Martins wrote: This is a bug, right? If not, why, and how can I get around it and call `method`? An alias refers just to a symbol, in this case a member function of struct X. The fact that you polled it on instance 'x' is not something an

Re: Error: need this for method of type

2019-10-23 Thread Dennis via Digitalmars-d-learn
On Wednesday, 23 October 2019 at 11:48:29 UTC, Dennis wrote: You can change `method(1)` into `x.method(1)` and it should work. Wait, but that's only because the local alias and member function have the same name 'method'. I think you just have to keep the method name as a string instead of an