Re: Coreect way to create delegate for struct method.

2018-08-22 Thread Rene Zwanenburg via Digitalmars-d-learn
On Tuesday, 21 August 2018 at 21:29:38 UTC, Andrey wrote: Hello, This is a code: (...) test.handler = That's an internal pointer, and internal pointers are not allowed in structs precisely because of the issues you're running into: the pointer will be invalid after a move.

Re: Coreect way to create delegate for struct method.

2018-08-22 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 22 August 2018 at 07:03:02 UTC, Andrey wrote: but it is ugly... You can write a type that will hide it.

Re: Coreect way to create delegate for struct method.

2018-08-22 Thread Alex via Digitalmars-d-learn
On Wednesday, 22 August 2018 at 07:03:02 UTC, Andrey wrote: On Tuesday, 21 August 2018 at 22:52:31 UTC, Alex wrote: Maybe, like this: Thank you but here you use heap to create ab object. I want only on stack. I know that one can do this: test_handler.ptr = null; and in place of call this:

Re: Coreect way to create delegate for struct method.

2018-08-22 Thread Andrey via Digitalmars-d-learn
On Tuesday, 21 August 2018 at 22:52:31 UTC, Alex wrote: Maybe, like this: Thank you but here you use heap to create ab object. I want only on stack. I know that one can do this: test_handler.ptr = null; and in place of call this: handler.ptr = cast(void*) but it is ugly... Hmm, any

Re: Coreect way to create delegate for struct method.

2018-08-21 Thread Alex via Digitalmars-d-learn
On Tuesday, 21 August 2018 at 21:29:38 UTC, Andrey wrote: Hello, This is a code: import std.stdio; struct Test { static Test opCall() { Test test; test.handler = return test; } void one() const { writeln("In handler: Address = ", , "; Text = ", text); }

Coreect way to create delegate for struct method.

2018-08-21 Thread Andrey via Digitalmars-d-learn
Hello, This is a code: import std.stdio; struct Test { static Test opCall() { Test test; test.handler = return test; } void one() const { writeln("In handler: Address = ", , "; Text = ", text); } void execute() { text = "Inited!";