//---------- Test.h---------------------- 
..... 
void Show(int &n); 
void ExecFunction(int i, void ShowN(int &n)); 
..... 
//-----------Test.cpp-------------------- 
void CTestDlg::ShowN(int & n) 

        CString strMsg; 
        strMsg.Format ("%d",n); 
        MessageBox(strMsg); 
} void CTestDlg::ExecFunction(int n,void ShowN(int& n)) 

        showN(n); 
} void CTestDlg::call() 

         ExecFunction(5,ShowN); } 
VC6中编译时出现 
ExecFunc' : cannot convert parameter 2 from 'void (int)' to 'void (__cdecl *)(void)' 我知道大概是因为this指针的问题,但究竟怎么回事....,请告诉一下,先谢了! 
尽快结账 

解决方案 »

  1.   

    说是回调函数,,我怎么连CALLBACK都没有看到啊
      

  2.   

    其实就是传一个函数指针,我自己感觉更callback有点相似,让大家见笑了
      

  3.   

    Add To     void CALLBACK
      

  4.   

    好像英这样调用: ExecFunction(5,this->ShowN);
      

  5.   

    参考:
    ULONG CALLBACK AVMessageProc(AV_MSG* pMsg);
    USHORT BeginUserMessageProc(ULONG CALLBACK fp(AV_MSG*))
      

  6.   

    使用了一个类的非静态成员函数,他增加了一个 this 指针作为参数,所以参数不匹配。至于 CALLBACK 可以使用或不使用,如果是让 Windows 调用,就使用。
    如果 void ExecFunction(int i, void( *ShowN)(int &n)); 
    的声明,ShowN 函数就不能使用 CALLBACK, 
    要使用 CALLBACK,则定义时:void ExecFunction(int i, void(CALLBACK *ShowN)(int &n)); 就是 ShowN 的定义应该如 函数参数的声明中的一致!
      

  7.   

    若以下为CTestDlg的非static成员:void Show(int &n);
    void ExecFunction(int i, void ShowN(int &n));
    则应将ExecFunction声明为:
    typedef void (CTestDlg::* ShowPointer)(int& n);
    void ExecFunction(int i,ShowPointer sp);修改:
    void CTestDlg::ExecFunction(int n, ShowPointer sp)
    {
        (this->*sp)(n);
    }