C++ 由于包含防护装置,类型不完整
我正试图编译一个项目,但我遇到了一个类型不完整的问题。以下是make的输出:C++ 由于包含防护装置,类型不完整,c++,C++,我正试图编译一个项目,但我遇到了一个类型不完整的问题。以下是make的输出: In file included from ../common/ClientCommunication.h:13, from EchoService_stub.h:9, from EchoService_stub.cpp:1: ../common/Naming_stub.h:16: error: field ‘clientCommunication’
In file included from ../common/ClientCommunication.h:13,
from EchoService_stub.h:9,
from EchoService_stub.cpp:1:
../common/Naming_stub.h:16: error: field ‘clientCommunication’ has incomplete type
In file included from EchoService_stub.h:9,
from EchoService_stub.cpp:1:
../common/ClientCommunication.h:20: error: field ‘serverEndpoint’ has incomplete type
make: *** [EchoService_stub.o] Error 1
以下是我的头文件:
在命名_stub.h中:
ifndef NAMING_STUB_H__
#define NAMING_STUB_H__
#include <string>
#include <string.h>
#include "Naming.h"
class ClientCommunication;
class Naming_stub : public Naming {
private:
ClientCommunication clientCommunication;
protected:
// Protected Methods Here.
public:
// Public Methods Here.
};
#endif
最后是ClientCommunication.h文件:
#ifndef CLIENT_COMMUNICATION_H__
#define CLIENT_COMMUNICATION_H__
#include <iostream>
#include <cstdlib>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include "../util/RemoteTypes.h"
#include "Naming_stub.h"
struct Endpoint;
class ClientCommunication {
private:
int socket_fd;
struct Endpoint serverEndpoint;
protected:
public:
ClientCommunication(const struct Endpoint& serverEndpoint_in);
struct Buffer send(struct Buffer& callBuffer);
~ClientCommunication();
};
#endif // CLIENT_COMMUNICATION_H__
\ifndef客户端通信\u H__
#定义客户端通信__
#包括
#包括
#包括
#包括
#包括
#包括“./util/RemoteTypes.h”
#包括“命名_stub.h”
结构端点;
类客户端通信{
私人:
int-socket_-fd;
结构端点服务器端点;
受保护的:
公众:
客户端通信(const struct Endpoint和serverEndpoint_in);
结构缓冲区发送(结构缓冲区和调用缓冲区);
~ClientCommunication();
};
#endif//客户端通信__
抱歉,这太长了,但还有一个头文件。端点结构在RemoteTypes.h中声明,如下所示:
#ifndef REMOTE_EXCEPTION_H__
#define REMOTE_EXCEPTION_H__
#include <netinet/in.h>
struct Endpoint {
int port;
char* service_id;
char* server_ip;
struct sockaddr_in host_name;
};
struct Buffer {
char* contents;
int size;
};
#endif
\ifndef远程异常\u H__
#定义远程异常__
#包括
结构端点{
国际港口;
字符*服务标识;
字符*服务器ip;
主机名中的结构sockaddr_;
};
结构缓冲区{
字符*内容;
整数大小;
};
#恩迪夫
谢谢
ClientCommunication
应在Naming_stub.h
声明之前在Naming_stub
中完整声明,或者其ClientCommunication
成员应成为指针/引用。只有那些类型不完整的才能工作。类似的建议适用于客户端通信中的端点
。h
客户端通信
应在命名存根.h
声明之前在命名存根
中完全声明,或者其客户端通信
成员应成为指针/引用。只有那些类型不完整的才能工作。类似的建议适用于ClientCommunication.h中的Endpoint
,您不能使用不完整的类型声明字段。您必须声明一个指针
private:
ClientCommunication clientCommunication; // requires #include
ClientCommunication *clientCommunication; // works with incomplete type
否则,您必须在第一个头中包含客户端通信头
ifndef NAMING_STUB_H__
#define NAMING_STUB_H__
#include "ClientCommunication.h"
不能使用不完整的类型声明字段。您必须声明一个指针
private:
ClientCommunication clientCommunication; // requires #include
ClientCommunication *clientCommunication; // works with incomplete type
否则,您必须在第一个头中包含客户端通信头
ifndef NAMING_STUB_H__
#define NAMING_STUB_H__
#include "ClientCommunication.h"
据我所知,你没有任何地方包括“ClientCommunication.h”或“RemoteTypes.h”
所以,#在ClientCommunication.h中包含“RemoteTypes.h”和#在命名_stub.h中包含“ClientCommunication.h”据我所知,您在任何地方都没有#include“ClientCommunication.h”或#include“RemoteTypes.h”
因此,#在ClientCommunication.h中包含“RemoteTypes.h”和#在命名_stub.h中包含“ClientCommunication.h”不要在标识符中使用双下划线。不要在标识符中使用双下划线。