gpt4 book ai didi

c++ - 头文件中定义的线程函数给​​出类型转换错误

转载 作者:太空宇宙 更新时间:2023-11-04 16:22:15 25 4
gpt4 key购买 nike

<分区>

请看下面的代码

Server.h

#pragma once
class Server
{
public:
Server(void);
~Server(void);

DWORD WINAPI serverThread(LPVOID param);

private:
SOCKADDR_STORAGE from;
int retval, fromlen, socket_type;
char servstr[NI_MAXSERV],hoststr[NI_MAXHOST];
SOCKET serverSocket, acceptSocket;
};

服务器.cpp

此处显示一小部分。

Server:Server()
{
//Code

//Passing data to thread
DWORD threadId;
HANDLE hdl;

hdl = CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE) serverThread,(LPVOID)acceptSocket,0,&threadId);

//Code
}


DWORD WINAPI Server::serverThread(LPVOID param)
{
//code
}

这段代码产生了错误

 error C2440: 'type cast' : cannot convert from 'overloaded-function' to 'LPTHREAD_START_ROUTINE'

即从行

hdl = CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE) serverThread,(LPVOID)acceptSocket,0,&threadId);

这是为什么?请帮忙!

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com