mardi 24 mars 2015

How can I call my set my callback function from an object?

Here is some code:



typedef void (*ACallBack)(int i, void* userData);

class SomeClass
{
private:
ACallBack aCallBack;

public:
void SetCallBack(ACallBack aCallBack, void* userData = NULL);
};

void SomeClass::SetCallBack(ACallBack aCallBack, void* userData)
{
this->aCallBack = aCallBack;
}

class SomeOtherClass
{
private:
SomeClass someClass;

public:
void InitializeSomeClass();

private:
void callBackMethod(int i, void* userData);
};

void SomeOtherClass::InitializeSomeClass()
{
this->changeVariable = 10;

this->someClass.SetCallBack(this->callBackMethod); // DOESN'T WORK
this->someClass.UseCallBack();
}

void SomeOtherClass::callBackMethod(int i, void* userData)
{
}

void globalCallBack(int i, void* userData)
{
int myInt = i;
}

int main()
{
SomeClass sC;
sC.SetCallBack(globalCallBack); //WORKS!!
}


Basically if I try to set my callback function in SomeOtherClass it doesn't work but when I set it globally in main it does. What am I missing here?


Aucun commentaire:

Enregistrer un commentaire