How do I return a function and then call it later?
So let's say I have this structure a and a void method that takes this structure as a parameter. How can I return a void method using another method and then call it later?
The code I have is as follows:
struct Script{
//variables
}
void foo(Script e)
{
}
function getfoo()
{
return foo;
}
void main(string[] args)
{
writeln("Hello World!");
stdin.readln();
}
+3
me me
source
to share
1 answer
import std.stdio;
struct Script
{
int x, y;
}
void foo(Script e)
{
writeln("Got: ", e);
}
void function(Script e) getfoo()
{
return &foo;
}
void main(string[] args)
{
auto func = getfoo();
func(Script(1, 2));
}
+8
Andrej Mitrović
source
to share