I have a function Foo
which takes a 2-parameter function as a parameter:
void Foo(void (*fcn)(int, int*));
However, the type of function which I want to pass in (func
) only takes 1 parameter*.
typedef void (__stdcall *FuncCallBack)(int a);
void Caller(FuncCallBack func) {
Foo(????);
}
In C#, I would do something like:
Foo((a,b) -> func(a));
I'm trying to do something similar with a delegate class (having worked out that I can't have a pointer to a bound member function, I've switched to static):
class Delegate {
private:
static FuncCallBack _Callback;
public
Delegate(FuncCallBack);
static void Callback(int, int*);
}
Delegate::Delegate(FuncCallback callback) { _Callback = callback; }
void Delegate::Callback(int a, int *b) { _Callback(a); }
Which I use like so:
void Caller(FuncCallBack func) {
Delegate d = Delegate(func);
Foo(&(d.Callback));
}
This is currently giving me a linker error: unresolved external symbol "private: static void (__stdcall* Delegate::_Callback)(int)" (?_Callback@Delegate@@0P6GXHHPAN0@ZA)
- Question 1: What could be causing this linker error?
- Question 2: Is there a better way to do this?
*The function typedef includes __stdcall
because it is passed in from (and will be calling back to) C#)