我想实例化一个函数指针:
static void GetProc (out function f) {
auto full = demangle(f.mangleof);
auto name = full[full.lastIndexOf('.')+1..$];
f = cast(typeof(f)) GetProcAddress(hModule,name.toStringz);
}
Run Code Online (Sandbox Code Playgroud)
但编译器不会让我使用函数类型变量(out function f).我试过用Object但显然function不是Object(怎么回事?).那么,我如何传递functionas ref/ outvariable(不使用template/ mixin,它会掩盖代码并迫使我添加许多typeof语句......)?
没有叫做的类型function.函数必须指定返回类型和参数类型int function(double, string).如果要支持任何类型的功能,请使用模板
static void GetProc(T)(out T f) if (isFunctionPointer!T)
...
Run Code Online (Sandbox Code Playgroud)