OMNET ++如何保留AODVRouting类中的所有功能,但仅覆盖sendAODVPacket函数? [英] OMNET++ How to retain all functions in AODVRouting class but override sendAODVPacket function only?

查看:146
本文介绍了OMNET ++如何保留AODVRouting类中的所有功能,但仅覆盖sendAODVPacket函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm writting a simple module to simulate a misbehaved node that inherits all functions from AODRouting, and overriding sendAODVPacket function by dropping the AODV packet once it has received it. The .h file as follows:

#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");
    }
}

当我重建项目时,出现以下错误:

When I rebuild my project, i got these error:

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

有什么办法解决这个问题吗?

Any ideas how to fix this?

推荐答案

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

The method sendAODVPacket() is declared in AODVRouting.h without virtual. You should add virtual before declaration of sendAODVPacket() in AODVRouting class in AODVRouting.h

这篇关于OMNET ++如何保留AODVRouting类中的所有功能,但仅覆盖sendAODVPacket函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆