How to pass ref/out function pointer to a function?

162 views Asked by At

I want to instantiate a function pointer:

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);
}

But the compiler won't let me use a function-type variable (out function f). I tried using Object but apparently function is not an Object (how-come??). So, how do I pass a function as ref/out variable (without using template/mixin, which obscures the code and forces me to add many typeof statements...) ?

1

There are 1 answers

5
kennytm On BEST ANSWER

There is no type called function. A function must specified the return type and argument type like int function(double, string). If you want to support any kind of function, use a template

static void GetProc(T)(out T f) if (isFunctionPointer!T) 
  ...