static member function as pointer to a function?

I'm writing RTSP client and after creating it with

class RtspClientManager
{
private:
    rtsp_client;
    void continueAfterDescribe(RTSPClient* rtspClient, int resultCode, char* resultString);
}

...

rtsp_client = RTSPClient::createNew(*env, szUrl);

i'm sending describe command:

rtsp_client->sendDescribeCommand(continueAfterDescribe);

I would like to have a continueAfterDescribe as RtspClientManager::continueAfterDescribe instance member and have access to all the members.

Of course continueAfterDescribe could be a static member function but then I would only have access to static members. How to pass a pointer to a non-static member function and have access to all instance members within RtspClientManager??

RTSPClient method sendDescribeCommand has such signature:

unsigned RTSPClient::sendDescribeCommand(responseHandler* responseHandler);

typedef void (responseHandler)(RTSPClient* rtspClient,
             int resultCode, char* resultString);

You can't. You have to use static function. But in your situation you can pass a RtspClientManager object as a parameter to the function and then use other methods/members of that object. Also your declarations are not correct, they should be like this:

typedef void (*responseHandler)(RTSPClient* rtspClient,
         int resultCode, char* resultString);

unsigned RTSPClient::sendDescribeCommand(responseHandler responseHandler);
链接地址: http://www.djcxy.com/p/96380.html

上一篇: 类构造函数中的静态函数指针

下一篇: 静态成员函数作为函数的指针?