OMNET++ 如何保留 AODVRouting class 中的所有功能,但仅覆盖 sendAODVPacket 功能?

OMNET++ How to retain all functions in AODVRouting class but override sendAODVPacket function only?

我正在编写一个简单的模块来模拟行为异常的节点,该节点继承了 AODRouting 的所有功能,并通过在收到 AODV 数据包后丢弃它来覆盖 sendAODVPacket 功能。 .h文件如下:

#ifndef __PROJECT1_SELFISHBASENODE_H_
#define __PROJECT1_SELFISHBASENODE_H_

#include <omnetpp.h>
#include "AODVRouting.h"

using namespace inet;

class SelfishBaseNode : public AODVRouting
{

protected:
virtual void initialize();
virtual void sendAODVPacket(AODVControlPacket *packet, const L3Address&     destAddr, unsigned int timeToLive, double delay) override;

};

#endif

CC文件如下:

#include "SelfishBaseNode.h"
#include <string.h>
#include <omnetpp.h>

Define_Module(SelfishBaseNode);

void SelfishBaseNode::initialize()
{
}


void SelfishBaseNode::sendAODVPacket(AODVControlPacket *packet, const L3Address& destAddr, unsigned int timeToLive, double delay)
{
    EV << "Received message, dropping message now\n";
    delete packet;
}

.NED文件如下:

package project1;


import inet.node.aodv.AODVRouter;

module snode extends AODVRouter
{
    parameters:
    //@networkNode;
    @display("i=device/wifilaptop");
    @labels(wireless-node);
    @class(SelfishBaseNode);

       submodules:
        bad: SelfishBaseNode {
        @display("p=273,350");
    }
}

当我重建我的项目时,我得到了这些错误:

SelfishBaseNode.h:35:18: error: 'sendAODVPacket' marked 'override' but does not override any member functions.

有什么解决办法吗?

方法 sendAODVPacket()AODVRouting.h 中声明而没有 virtual。您应该在 AODVRouting class 中 AODVRouting.h

中声明 sendAODVPacket() 之前添加 virtual