【发布时间】: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)
【问题讨论】: