c++ - _beginthreadex 静态成员函数

标签 c++ function static multithreading member

如何创建静态成员函数的线程例程

class Blah
{
    static void WINAPI Start();
};

// .. 
// ...
// ....

hThread = (HANDLE)_beginthreadex(NULL, 0, CBlah::Start, NULL, NULL, NULL);

这给了我以下错误:

***error C2664: '_beginthreadex' : cannot convert parameter 3 from 'void (void)' to 'unsigned int (__stdcall *)(void *)'***

我做错了什么?

最佳答案

有时,阅读您遇到的错误很有用。

cannot convert parameter 3 from 'void (void)' to 'unsigned int (__stdcall *)(void *)'

让我们看看它说了什么。对于第三个参数,您给它一个带有签名 void(void) 的函数,即一个不接受任何参数且不返回任何内容的函数。它无法将其转换为 unsigned int (__stdcall *)(void *),这正是 _beginthreadex 期望:

它需要一个函数:

  • 返回一个unsigned int:
  • 使用stdcall调用约定
  • 采用 void* 参数。

所以我的建议是“给它一个带有它要求的签名的函数”。

class Blah
{
    static unsigned int __stdcall Start(void*);
};

关于c++ - _beginthreadex 静态成员函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1259815/

相关文章:

c++ - 停止运行 exe 文件 C++

python - 函数恰好需要 2 个参数(给定 4 个)

c - 数组参数中的数组长度

java - 哪个先加载?静态 block 还是 spring bean?

c++ - 什么时候在 C/C++ 中分配静态内存?在编译时还是在程序运行的最开始?

c++ - 从函数绘制图形

c++ - 我们可以为 int 或 float 等内置类型重载运算符吗?

c++ - 在 QML 中使用 C++-slot 返回命名空间中的类型

function - FORTRAN 95 在使用函数和函数中的预期形式参数列表时出现主程序错误

c - IF 语句正在更改函数中的数组元素