gpt4 book ai didi

C++ 头重新定义 (ws2ipdef.h)

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

我在我的项目中使用了很多包含(但每个头文件都使用像

#ifndef _HEADER_H 
#define _HEADER_H
...
#endif

现在我从 ws2ipdef.h(自动包含在 windows.h 中)得到这个错误:

c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(336) : error C2146: syntax error : missing ';' before identifier 'IN6_ADDR_EQUAL'
1>c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(336) : error C2433: 'Boolean' : 'inline' not permitted on data declarations
1>c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(336) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(337) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(344) : error C2064: term does not evaluate to a function taking 1 arguments
1>c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(344) : warning C4508: 'IN6_ADDR_EQUAL' : function should return a value; 'void' return type assumed
1>c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(354) : error C2146: syntax error : missing ';' before identifier 'IN6_IS_ADDR_UNSPECIFIED'
1>c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(354) : error C2433: 'Boolean' : 'inline' not permitted on data declarations
1>c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(354) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(354) : error C2086: 'int Boolean' : redefinition
1> c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(336) : see declaration of 'Boolean'
1>c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(355) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(367) : error C2064: term does not evaluate to a function taking 1 arguments
1>c:\program files\microsoft sdks\windows\v7.0\include\ws2ipdef.h(367) : warning C4508: 'IN6_IS_ADDR_UNSPECIFIED' : function should return a value; 'void' return type assumed

在 Interface.h(包含在其他一些文件中)我使用:

#define WIN32_LEAN_AND_MEAN

// sockets
#include <winsock2.h>
#include "windows.h"
#include <ws2tcpip.h>

我该如何解决这个问题或任何提示?

谢谢

最佳答案

尝试使用 #pragma once 而不是 ifndef guard,它指定编译器在编译源代码文件时只包含(打开)一次该文件。 http://msdn.microsoft.com/en-us/library/4141z1cx.aspx

关于C++ 头重新定义 (ws2ipdef.h),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13376616/

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