回调函数和普通函数的区别

来源:互联网 发布:js修改parameter 编辑:程序博客网 时间:2024/04/29 08:56


 

1、区别不是太大:

普通函数被调用时,必须执行完毕之后才能才开始继续执行主调函数。如int a = run(GetPath());

回调函数被调用时,可以一边执行该回调函数,一边执行主调函数,多见于线程,作为线程的参数。如:

unsigned long ulThreadResult = (unsigned long)_beginthreadex(NULL,0,(unsigned (__stdcall*)(void*))GetPath,NULL,0,NULL);


2、普通函数被调用时,主调函数会直接调用。

      回调函数被调用时,主调函数会通过调用其他函数间接地调用回调函数。

如:

void func1(){}
void func2(){}

void funcCaller3()

{
    funcCaller2(func1);//调用funcCaller2,参数是func1。因此,funcCaller2是普通函数,func1是回调函数
    funcCaller2(func2);//调用funcCaller2,参数是func2因此,funcCaller2是普通函数,func2是回调函数
}


0 0
原创粉丝点击