我正在尝试为UDP服务器创建客户端列表。
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include "stdafx.h"
#include <map>
#include <unordered_map>
#include <WS2tcpip.h>
#include <WinSock2.h>
#include <Windows.h>
#pragma comment(lib, "Ws2_32.lib")
std::map<sockaddr_in, int> clientList;
....
void Listen(){
sockaddr_in client;
[...]
if (clientList.find(client) == clientList.end()) {
printf("Got a new client!\n");
std::pair<sockaddr_in, uint64_t> item(client, rand());
clientList.insert(item);
}
}
我收到以下错误:
C2678 binary '<': no operator found which takes a left-hand operand of type 'const sockaddr_in'
我也尝试使用unordered_map,它给出了以下错误:
C2280 'std::hash<_Kty>::hash(const std::hash<_Kty> &)' :attempting to reference a deleted function
当我只声明地图时它编译得很好。我似乎无法弄清楚自从sockaddr_in由WinSock2定义以来出了什么问题。我正在使用VS2017。