gpt4 book ai didi

c++ - SOCKET 没有命名类型

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

如问题所述,我遇到以下代码问题:

#pragma once
#include "includes.h"
#include "buffer.h"


class CSocket
{
bool udp;
int format;
char formatstr[30];
static sockaddr SenderAddr;
int receivetext(char*buf, int max);
public:

SOCKET sockid;
CSocket(SOCKET sock);
CSocket();
~CSocket();
bool tcpconnect(char*address, int port, int mode);
bool tcplisten(int port, int max, int mode);
CSocket* tcpaccept(int mode);
char* tcpip();
void setnagle(bool enabled);
bool tcpconnected();
int setsync(int mode);
bool udpconnect(int port, int mode);
int sendmessage(char*ip, int port, CBuffer* source);
int receivemessage(int len, CBuffer*destination);
int peekmessage(int size, CBuffer*destination);
int lasterror();
static char* GetIp(char*address);
static int SockExit(void);
static int SockStart(void);
static char* lastinIP(void);
static unsigned short lastinPort(void);
static char* myhost();
int SetFormat(int mode, char* sep);
};

我正在使用 Code::Blocks。我在构建时遇到以下错误:

/home/nick/Desktop/39dylibsource/Base Code/39dll/socket.h|15|error: ‘SOCKET’ does not name a type|
/home/nick/Desktop/39dylibsource/Base Code/39dll/socket.h|16|error: expected ‘)’ before ‘sock’|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|16|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|25|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|34|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|43|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|50|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|59|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|66|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|74|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|85|error: expected constructor, destructor, or type conversion before ‘(’ token|
||=== Build finished: 11 errors, 0 warnings ===|

我在引用的 includes.h 中包含了以下内容:

#include <sys/socket.h>
#include <sys/types.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>

我是否缺少指令或库? SOCKET 拼写不同吗?任何照明都会很棒!

最佳答案

套接字文件描述符只是一个整数。因此,在您的代码中将 SOCKET 替换为 int,或者使用 typedef。 (我不确定您以前在哪里看到过 SOCKET,但它不是标准的。)

关于c++ - SOCKET 没有命名类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11372036/

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