![](/img/trans.png)
[英]C++ - What does “Incomplete type not allowed” error mean, and how can I fix it?
[英]How can i solve the incomplete type error in c++?
我正在使用omnetpp v4.6的INET Framework 3.2.2。 我的代码正在从INET框架导入.h文件,但是即使我在代码引用中添加了INET框架并且我已经在#include中写入了完整的路径目录,并且向前声明了我需要的类,但它仍然无法识别我正在使用的属性,并给我“不完整的类型”错误,但它们在内联布尔运算符中被很好地识别,没有错误。 这是代码:
#ifndef OPENFLOW_H_
#define OPENFLOW_H_
#define OFP_VERSION 0x01
#include "inet/common/INETDefs.h"
//doesn't recognize the includes
#include <inet/networklayer/contract/ipv4/IPv4Address.h>
#include <inet/linklayer/common/MACAddress.h>
class MACAddress;
class IPv4Address;
struct oxm_basic_match {
int OFB_IN_PORT;
MACAddress OFB_ETH_DST; //error (field 'OFB_ETH_DST' has incomplete type 'MACAddress')
MACAddress OFB_ETH_SRC; //error (field 'OFB_ETH_SRC' has incomplete type 'MACAddress')
int OFB_ETH_TYPE;
IPv4Address OFB_IPV4_DST; //error (field 'OFB_IPV4_DST' has incomplete type 'IPv4Address')
int OFB_ARP_OP; /* ARP opcode. */
IPv4Address OFB_ARP_SPA; /* ARP source IPv4 address. */ //error (field 'OFB_ARP_SPA' has incomplete type 'IPv4Address')
IPv4Address OFB_ARP_TPA; /* ARP target IPv4 address. */ //error (field 'OFB_ARP_TPA' has incomplete type 'IPv4Address')
MACAddress OFB_ARP_SHA; /* ARP source hardware address. */ //error (field 'OFB_ARP_SHA' has incomplete type 'MACAddress')
MACAddress OFB_ARP_THA; /* ARP target hardware address. */ //error (field 'OFB_ARP_THA' has incomplete type 'MACAddress')
uint32_t wildcards;
int getPriority();
};
inline bool operator==(const oxm_basic_match &m1, const oxm_basic_match& m2) {
return m2.OFB_IN_PORT == m1.OFB_IN_PORT
&& m2.OFB_ETH_DST == m1.OFB_ETH_DST
&& m2.OFB_ETH_SRC == m1.OFB_ETH_SRC
&& m2.OFB_ETH_TYPE == m1.OFB_ETH_TYPE
&& m2.OFB_ARP_OP == m1.OFB_ARP_OP
&& m2.OFB_ARP_SHA == m1.OFB_ARP_SHA
&& m2.OFB_ARP_SPA == m1.OFB_ARP_SPA
&& m2.OFB_ARP_THA == m1.OFB_ARP_THA
&& m2.OFB_ARP_TPA == m1.OFB_ARP_TPA;
}
请帮忙吗?
在这种情况下,您不能使用前向声明。 您应该包括包含完整类定义的头文件。 类MACAddress {...}
前向声明只能用于指针或引用。 这是一个更完整的答案- 什么时候可以使用前向声明?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.