好的,运行 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
服务.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 */
服务.cpp:
#include "services.h"
services::services()
{
//do nothing
}
services::~services()
{
//TODO: incase crash, log why.
}
int services::connect()
{
return 0;
}