I have a class, in which i declare a static function. I register this function as the callback function for another library. Now, inside this function, i dereference the callback data to the class pointer and invoke a particular non-static member.
The invocation succeeds and the control comes into the non-static member function. But inside this function at the point where i access a member variable of the same class, i get a segmentation fault. This is strange. Can anybody help me with the possible mistake i have made and the solution?
Here is how the code looks like.
class test
{
int count;
int callback(const char * a, const char *b)
{
print(a);
print(b);
count++; //// HERE IS WHERE I GET THE SEGMENTATION FAULT
}
public:
static int callbackwrapper(const char*a, const char *b, void *ptr)
{
test *p = (test *)ptr;
p->callback(a, b);
}
test():count(0) {}
~test() {}
Register()
{
registercallback(callbackwrapper);
}
}