OMNET ++如何保留AODVRouting类中的所有函数但仅覆盖sendAODVPacket函数?

时间:2017-07-20 03:45:46

标签: c++ omnet++ inet

我正在编写一个简单的模块来模拟一个行为不端的节点,该节点继承了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.

任何想法如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

方法sendAODVPacket()AODVRouting.h中声明,但没有virtual。您应在[{1}}

中的virtual课程中声明sendAODVPacket()之前添加AODVRouting