gpt4 book ai didi

c++ - 使用 MAKEWORD 函数会产生错误 E0109- 明显调用的括号前的表达式必须具有(指向-)函数类型

转载 作者:太空宇宙 更新时间:2023-11-04 12:35:02 35 4
gpt4 key购买 nike

我正在使用 cpp、套接字、json 和 winsock2 编写一个项目来创建服务器和客户端之间的连接,我正在使用 winsock2.h 中的函数 WSAStartup 来启动连接。我从互联网上的代码中复制了它的使用方式,并运行了一段时间,直到 MAKEWORD 函数突然产生错误。

这是我在其中使用 MAKEWORD 的函数:(Communicator、RequestHandlerFactory 和m_handlerFactory 是我创建的类,请忽略)

Communicator::Communicator(RequestHandelerFactory* RHF) : m_handlerFactory(RHF)
{
WSADATA wsa_data = {};
if (WSAStartup(MAKEWORD(2, 2), &wsa_data) != 0)
{
throw std::exception("wsa startup failed");
}
std::cout << "Starting..." << std::endl;
_serverSocket = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (_serverSocket == INVALID_SOCKET)
{
throw std::exception(__FUNCTION__ " - socket");
}
}

我使用的包含和定义:

#pragma warning(disable : 4996)
#define WIN32_LEAN_AND_MEAN

#include <Windows.h>
#include <WinSock2.h>
#include <WS2tcpip.h>
#include <stdio.h>
#include <sstream>
#include <bitset>
#include <exception>
#include <minwindef.h>
#include <windef.h>
#include <ctime>
//some more includes from code I wrote

#pragma comment (lib, "ws2_32.lib")

错误出现在 MAKEWORD 函数中,无论我做什么,它仍然给出相同的错误。

E0109 expression preceding parentheses of apparent call must have (pointer-to-) function type

我使用的是 Visual Studio 2017,如果它有任何改变的话。我尝试了很多方法来解决这个问题,但似乎没有任何效果。

最佳答案

问题是在我的代码之前使用了define。谢谢:)

关于c++ - 使用 MAKEWORD 函数会产生错误 E0109- 明显调用的括号前的表达式必须具有(指向-)函数类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56807352/

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