How to access non static class members inside static method of the same class

I have a class with method send which will use curl to send something and handlehdr is the callback function for receiving the headers. curl_easy_setopt doesn't accept non static methods as callback.
I can make it static member but i want to access the data members of class A inside header_callback. How do i do this?

Should i have this header_callback method outside the class and create instance of class A inside that method to access its members? Since this method is callback inside class A's method (send), is there any other way to do this?

class A
{
public:
int a;
string str;
-------
------
void send();
size_t header_callback(char *buffer, size_t size,
size_t nitems, void *userdata);
}


void A::send()
{
---------
---------
curl_easy_setopt(multi_handle, CURLOPT_HEADERFUNCTION, header_callback);
curl_multi_perform(curl_multi_perform(multi_handle, &still_running));
}

size_t A::header_callback(char *buffer, size_t size,
size_t nitems, void *userdata)
{

//want to access class A's non static data members here
}
That's what the fourth argument to header_callback argument is. User data.

1
2
3
4
5
6
7
8
9
10
11
12
class A 
{
  void header_callback(char *buf, size_t sz, size_t n) const;
  friend void header_callback_thunk(char* buf, size_t sz, size_t n, void* ptr);
};

void header_callback_thunk(char* buf, size_t sz, size_t n, void* ptr)
{ static_cast<A const*>(ptr)->header_callback(buf, sz, n); }
// ...
A a;
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback_thunk);
curl_easy_setopt(curl, CURLOPT_HEADERDATA, &a);

Last edited on
Actually i have another structure which holds some info as HEADERDATA, i think i can have &a as one of the fileds in that structure. Thank you so much.
Topic archived. No new replies allowed.