I have the following header:
class MyClass {
private:
static void (*OnRequest)();
static void (*OnReceive)(int numBytes);
public:
MyClass();
static void SetOnReceive(void (*function)(int));
static void SetOnRequest(void (*function)(void));
};
void NonClassFunction();
and the following declaration:
#include "MyClass.h"
MyClass::MyClass() {
...
}
void MyClass::SetOnReceive(void (*function)(int) ) {
OnReceive = function;
}
void MyClass::SetOnRequest( void (*function)(void) ) {
OnRequest = function;
}
void NonClassFunction() {
MyClass::OnRequest();
}
The code compiles fine but I get the following errors when I link:
unresolved symbol MyClass::OnReceive, first referenced in ./src/MyClass.obj
unresolved symbol MyClass::OnRequest, first referenced in ./src/MyClass.obj
I need OnRequest and OnReceive to function like a callback through NonClassFunction(). The NonClassFunction is being called by an interrupt so there is a bit of object oriented mangling going on here. MyClass is designed to be inherited. Ideally I would like OnRequest and OnReceive to be virtual but you cannot make static methods virtual.