【问题标题】:OMNET++ How to retain all functions in AODVRouting class but override sendAODVPacket function only?OMNET++ 如何保留 AODVRouting 类中的所有功能,但只覆盖 sendAODVPacket 功能?
【发布时间】:2017-07-21 06:25:02
【问题描述】:

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

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

【问题讨论】:

    标签: c++ omnet++ inet


    【解决方案1】:

    方法sendAODVPacket()AODVRouting.h中声明,没有virtual。您应该在 AODVRouting 类中 AODVRouting.hsendAODVPacket() 声明之前添加 virtual

    【讨论】:

      猜你喜欢
      • 2023-03-28
      • 1970-01-01
      • 2012-09-28
      • 1970-01-01
      • 1970-01-01
      • 2021-02-07
      • 2017-11-17
      • 2016-10-20
      • 1970-01-01
      相关资源
      最近更新 更多