I'm trying to interface a c++ member function with a legacy C library taking a function pointer - I can't see why this keeps coming up with link errors, Can anyone see why ?
link errors
/tmp/ccl2HY1E.o: In function `VerifyWrapper::verifyGlue(int)': callback.cpp:(.text._ZN13VerifyWrapper10verifyGlueEi[VerifyWrapper::verifyGlue(int)]+0xe): undefined reference to `VerifyWrapper::vfy'
/tmp/ccl2HY1E.o: In function `VerifyWrapper::set(Verify&)': callback.cpp:(.text._ZN13VerifyWrapper3setER6Verify[VerifyWrapper::set(Verify&)]+0xf): undefined reference to `VerifyWrapper::vfy'
compile with: g++ callback.cpp -o callback
#include <iostream>
using namespace std;
class Verify
{
public:
int verify(int i) { return i * 2; };
};
class VerifyWrapper
{
public:
static int verifyGlue(int i) { return vfy->verify(i); };
static void set(Verify& v) { vfy = &v;};
private:
static Verify* vfy;
};
// legacy function
int func(int i, int(*f)(int))
{
int ret = f(i);
return ret;
}
int main(void)
{
int i = 10;
Verify v;
VerifyWrapper::set(v);
int ret = func(10, &VerifyWrapper::verifyGlue);
cout << "result : " << ret << endl;
return 0;
}