【问题标题】:Overriding Error in iNET framework in OMNET++OMNET++ 中 iNET 框架中的覆盖错误
【发布时间】:2021-01-01 23:07:54
【问题描述】:

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

#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”的无效新表达式

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 的增量构建 **** 使模式=释放所有 cd src && make all make[1]: 进入目录'/home/abbuser/Subhash/omnetpp-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' 标记为“覆盖”,但不覆盖 virtual void printMessage(std::ostream& os, cMessage msg) 常量覆盖; ^~~~~~~~~~~~ 在 /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:公共 cMessagePrinter ^~~~~~~~~~~~~~~~~~~~~~ 在 /home/abbuser/Subhash/omnetpp-5.6.1/include/omnetpp.h:68:0 包含的文件中, 来自./inet/common/INETDefs.h:28, 来自 inet/common/packet/InetPacketBytesPrinter.cc:18: /home/abbuser/Subhash/omnetpp-5.6.1/include/omnetpp/cmessageprinter.h:110:22:注意:virtual void omnetpp::cMessagePrinter::printMessage(std::ostream&, omnetpp::cMessage , 常量 omnetpp::cMessagePrinter::Options*) 常量 virtual void printMessage(std::ostream& os, cMessage *msg, const Options *options) const = 0; ^~~~~~~~~~~~ Makefile:1127:目标“../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: *** [全部] 错误 2 Makefile:4:目标“全部”的配方失败 “make MODE=release all”以退出代码 2 终止。构建可能不完整。

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

【问题讨论】:

    标签: c++ omnet++ inet


    【解决方案1】:

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

    【讨论】:

    • 谢谢! @Rudi 发表评论。我正在研究 LLDP(链路层检测协议),据我了解,较新版本的 iNET 不支持 LLDP...(如果我错了,请更正)
    • AFAIK,没有任何版本的 INET 具有 LLDP 实现,因此在这方面,您可以使用任何版本的 INET 作为起点。
    • 那么,您是否知道任何基于 OMNET++ 的框架对 LLDP 有一些见解?
    【解决方案2】:

    根据这个documentation cMessagePrinter::printMessage 方法需要三个参数,但您的版本只有两个,因此它不是覆盖。

    将您的 printMessage 签名更改为与您要覆盖的方法相同。

    【讨论】:

    • 谢谢@John!上述错误已得到解决,但这些修改在以下部分中产生了另一个错误:printMessage(os, packet->getEncapsulatedPacket()); ** 带有错误消息:*inet/common/packet/InetPacketPrinter.cc:198:61:错误:没有匹配函数调用 'inet::InetPacketPrinter::printMessage(std::ostream&, omnetpp::cPacket ) 常量'
    • @SubhashKumar 您所犯的总体错误是printMessage 方法需要三个参数,无论是在您覆盖它时还是在调用它时。您需要提供第三个 Options 参数。很抱歉,我对这个库不熟悉,所以我无法建议它应该是什么。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多