c++错误:??不命名类型

c++ error: ??? does not name a type

本文关键字:类型 c++ 错误      更新时间:2023-10-16

运行g++ main.cpp -o services

如果我在一个类中做所有这些,让我们说。cpp它工作得很好,但是每当我把它分成另一个类时,我一直得到错误,我真的不明白为什么,我所做的就是把代码移动到另一个文件,并包括它。

我被扔了:

[Admin@shadowrealm ircservices]$ g++ main.cpp -o services                       
In file included from services.cpp:1:0,
                 from main.cpp:4:
services.h:23:2: error: âSOCKETâ does not name a type
services.h:24:2: error: âHOSTENTâ does not name a type
services.h:25:2: error: âSOCKADDR_INâ does not name a type

services.h:

#ifndef SERVICES_H
#define SERVICES_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <stdarg.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
class services {
public:
    services(); //perhaps init something important here, dunno
    ~services();
    int connect();
private:
    SOCKET sock;
    HOSTENT* host;
    SOCKADDR_IN address;
};
#endif /* SERVICES_H */

services.cpp:

#include "services.h"
services::services()
{
//do nothing
}
services::~services()
{
//TODO: incase crash, log why.
}
int services::connect()
{
    return 0;
}

c++区分大小写。右边是

sockaddr_in
hostent

如果我没记错的话,SOCKET或SOCKET根本没有命名类型