首页 > 解决方案 > OMNET++ 中 iNET 框架中的覆盖错误

问题描述

即使工作区中的所有库都可用,我也收到错误“覆盖错误”。以下是带有提到错误的相关代码片段:

#include "inet/common/INETDefs.h"
namespace inet {
#if OMNETPP_VERSION >= 0x0405
class INET_API InetPacketBytesPrinter : public cMessagePrinter
{
protected:
mutable bool showEncapsulatedPackets;  
public:
InetPacketBytesPrinter() { showEncapsulatedPackets = true; }
virtual ~InetPacketBytesPrinter() {}
virtual int getScoreFor(cMessage *msg) const override;
virtual void printMessage(std::ostream& os, cMessage *msg) const override;
};

错误: “virtual void inet::InetPacketBytesPrinter::printMessage(std::ostream&, omnetpp::cMessage*) const”标记为“覆盖”,但不覆盖

Register_MessagePrinter(InetPacketBytesPrinter);

错误:抽象类类型“inet::InetPacketBytesPrinter”的无效新表达式</p>

static const char INFO_SEPAR[] = "  \t";
int InetPacketBytesPrinter::getScoreFor(cMessage *msg) const{
return msg->isPacket() ? 18 : 0;
}
void InetPacketBytesPrinter::printMessage(std::ostream& os, cMessage *msg) const
{
std::string outs;
showEncapsulatedPackets = true;
for (cPacket *pk = dynamic_cast<cPacket *>(msg); showEncapsulatedPackets && pk; pk = pk->getEncapsulatedPacket()) {    
    std::ostringstream out;
    out << pk->getClassName() << ":" << pk->getByteLength() << " bytes";
    if (outs.length())
        out << INFO_SEPAR << outs;
    outs = out.str();
}
os << outs;
}
#endif
}

控制台: 12:46: 31 **** 增量构建项目 ansainet 的配置 gcc-release **** make MODE=release all cd src && make all make[1]: 进入目录 '/home/abbuser/Subhash/ omn​​etpp-5.6.1/samples/ansainet/src'inet/common/packet/InetPacketBytesPrinter.cc inet/common/packet/InetPacketBytesPrinter.cc:33:18: 错误: 'virtual void inet::InetPacketBytesPrinter::printMessage(std: :ostream&, omnetpp::cMessage*) const' 标记为 'override',但不覆盖 virtual void printMessage(std::ostream& os, cMessage味精)常量覆盖;^~~~~~~~~~~~ 在 /home/abbuser/Subhash/omnetpp-5.6.1/include/omnetpp/globals.h:21:0 包含的文件中,来自 /home/abbuser/Subhash/omnetpp -5.6.1/include/omnetpp/cobjectfactory.h:20,来自/home/abbuser/Subhash/omnetpp-5.6.1/include/omnetpp.h:30,来自./inet/common/INETDefs.h:28,从 inet/common/packet/InetPacketBytesPrinter.cc:18: inet/common/packet/InetPacketBytesPrinter.cc: 在函数 'void inet::{anonymous}::__onstartup_func_36()': inet/common/packet/InetPacketBytesPrinter.cc: 36:1:错误:抽象类类型“inet::InetPacketBytesPrinter”Register_MessagePrinter(InetPacketBytesPrinter) 的无效新表达式;^ inet/common/packet/InetPacketBytesPrinter.cc:24:16: 注意:因为以下虚函数在 'inet::InetPacketBytesPrinter' 中是纯函数: 类 INET_API InetPacketBytesPrinter :, const omnetpp::cMessagePrinter::Options*) const virtual void printMessage(std::ostream& os, cMessage *msg, const Options *options) const = 0; ^~~~~~~~~~~~ Makefile:1127: recipe for target '../out/gcc-release/src/inet/common/packet/InetPacketBytesPrinter.o' 失败 make[1]: 离开目录' /home/abbuser/Subhash/omnetpp-5.6.1/samples/ansainet/src' make[1]: *** [../out/gcc-release/src/inet/common/packet/InetPacketBytesPrinter.o] 错误1 make: *** [all] Error 2 Makefile:4: recipe for target 'all' failed "make MODE=release all" 以退出代码 2 终止。构建可能不完整。

12:46:35 构建失败。6 个错误,0 个警告。(耗时 3s.328ms)

标签: c++omnet++inet

解决方案


您尝试构建的 INET 版本太旧,无法使用 OMNeT++ 5.6 构建。您应该使用较旧的 OMNeT++ 版本(在 INET 版本的 README 文件中指出),或者使用较新版本的 INET(可能是最新的 3.6.x 版本?)


推荐阅读