【问题标题】:no instance of overloaded function "AfxBeginThread" matches the argument list没有重载函数“AfxBeginThread”的实例与参数列表匹配
【发布时间】:2012-03-20 17:13:21
【问题描述】:

我正在尝试使用 MFC 创建一个工作线程,所以这里是代码:

struct ThreadParam
{
    HWND mDlg;    // Note: A handle.
};

UINT TestMFCThread::Test( LPVOID pParam ){
  //do work!
}
void TestMFCThread::OnBnClickedButton2()
{
    ThreadParam* param = new ThreadParam;
    param->mDlg = m_hWnd;
    AfxBeginThread(Test, param);
}

但它给了我这个错误:

1   IntelliSense: no instance of overloaded function "AfxBeginThread" matches the argument list
    argument types are: (UINT (LPVOID pParam), ThreadParam *)

idk whats wrong 它应该是正确的!

【问题讨论】:

    标签: c++ multithreading mfc


    【解决方案1】:

    AfxBeginThread() 的文档中,您需要将第二个参数转换为LPVOID

    AfxBeginThread(Test, (LPVOID) param);
    

    并将Test的调用约定设置为__cdecl

    UINT __cdecl Test( LPVOID lParam)
    

    【讨论】:

    • 我试过了,但它仍然给我错误1 IntelliSense: no instance of overloaded function "AfxBeginThread" matches the argument list argument types are: (UINT (LPVOID pParam), LPVOID)
    • 更新了关于调用约定的答案。
    • 即使在添加__cdecl 之后,它仍然给我参数错误1 IntelliSense: no instance of overloaded function "AfxBeginThread" matches the argument list argument types are: (UINT __cdecl (LPVOID pParam), LPVOID)
    • @MixedCoder:Test 是类中的方法吗?
    • 将其移出TestMFCThread类或声明static
    【解决方案2】:

    只需将你的成员函数声明为 static ,它就会解决问题

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 2019-07-16
    • 2013-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多