CODE:
typedef void (*DownloadFinishCallFunc)(DownloadTask* task, void* userData);
// 这里用typedef, 是用后者来替换前者,对吧?
DownloadFinishCallFunc callFunc; //这个很奇怪,DownloadFinishCallFunc明明是一个涵数指针.怎么这样定义呢
DownloadTask* curTask;
void* callFuncData;
SetFinishCallBack( DownloadManage::DownloadFinishedCallback, this );
void DownloadManage::DownloadFinishedCallback(DownloadThread::DownloadTask* task, void * data )
{
..............
}
void DownloadThread::SetFinishCallBack(DownloadFinishCallFunc func, void* userData)
{
callFunc = func;
callFuncData = userData;
}
当执行到这语句:
dlobject.m_dlThread->SetFinishCallBack( DownloadManage::DownloadFinishedCallback, this );
// 这里用typedef, 是用后者来替换前者,对吧?
DownloadFinishCallFunc callFunc; //这个很奇怪,DownloadFinishCallFunc明明是一个涵数指针.怎么这样定义呢
DownloadTask* curTask;
void* callFuncData;
SetFinishCallBack( DownloadManage::DownloadFinishedCallback, this );
void DownloadManage::DownloadFinishedCallback(DownloadThread::DownloadTask* task, void * data )
{
..............
}
void DownloadThread::SetFinishCallBack(DownloadFinishCallFunc func, void* userData)
{
callFunc = func;
callFuncData = userData;
}
当执行到这语句:
dlobject.m_dlThread->SetFinishCallBack( DownloadManage::DownloadFinishedCallback, this );
请问执行到这句之后会怎么调用.
我之前找了些资料:
void (*p) ();
void caller(void(*ptr)())
{
ptr(); /* 调用ptr指向的函数 */
}
void func();
int main()
{
p = func;
caller(p); /* 传递函数地址到调用者 */
}
没有评论:
发表评论