继承TIdTCPServer时出现的问题

疯狂的技术宅 2006-05-10 04:24:48
我想继承TIdServer生成一个新类,但是在编译时总是提示
[C++ Error] winsock2.h(109): E2238 Multiple declaration for 'fd_set'
[C++ Error] winsock.h(54): E2344 Earlier declaration of 'fd_set'
[C++ Error] winsock2.h(112): E2146 Need an identifier to declare
[C++ Error] winsock2.h(153): E2238 Multiple declaration for 'timeval'
[C++ Error] winsock.h(97): E2344 Earlier declaration of 'timeval'
。。。。
等等诸如此类的错误信息,大意是一些数据类型或结构在winsock2.h和winsock.h中重复定义了,我该怎样才能顺利编译呢?我用的是Indy9
源代码如下:
//------------------------------------------------------
//AlarmTCPServer.h
#include <classes.hpp>
#include <IdTCPServer.hpp>
class TAlarmTCPServer : public TIdTCPserver
{
public:
TAlarmTCPServer(Classes::TComponent* AOwner);
......
};
...全文
430 6 打赏 收藏 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
times99 2006-06-15
  • 打赏
  • 举报
回复
经过我的无数次试验,终于解决问题了。由于#include <ScktComp.hpp>导致增加了winsock2.h或winsock.h头文件。另外,如果你自己写了一个文件,其中包含了使用socket的API函数,例如ntohl等,如果出现以上问题,请使用以下语句,屡试屡爽! (在BCB、VC或UNIX中也可以以下相同的语句啊)

#ifdef _WIN32
# ifndef _WINSOCKAPI_
# define _WINSOCKAPI_
# endif
# include <winsock2.h>
//# pragma comment(lib, "ws2_32.lib")
# include <process.h>
# include <direct.h>
# include <io.h>
# if defined(_AFXDLL)
# include <afx.h>
# else
# include <windows.h>
# include <winbase.h>
# endif
#else //unix
#include <netinet/in.h>
#endif
疯狂的技术宅 2006-06-01
  • 打赏
  • 举报
回复
up
疯狂的技术宅 2006-05-19
  • 打赏
  • 举报
回复
我没有include winsock2.h和winsock.h 文件,但是却显示上面的出错信息。
有对Indy比较熟悉的高手吗
铖邑 2006-05-11
  • 打赏
  • 举报
回复
winsock2.h和winsock.h只要一个就够了
疯狂的技术宅 2006-05-11
  • 打赏
  • 举报
回复
楼上请明示
pp616 2006-05-10
  • 打赏
  • 举报
回复
干吗要2个头文件都include ??

1,317

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧