我收到很多错误,例如"重新宣布"和#34;班级没有注册"当我尝试从inet扩展一个简单的模块时。甚至可以在inet.src目录之外扩展模块吗?
MyMac.ned
package myproject.linklayer;
import inet.linklayer.contract.IMACProtocol;
import inet.linklayer.base.MACProtocolBase;
simple MyMac extends MACProtocolBase like IMACProtocol
{
parameters:
@display("i=block/rxtx");
@class(MyMac);
}
MyMac.h
#ifndef __INET_MYMAC_H
#define __INET_MYMAC_H
#include "inet/linklayer/base/MACProtocolBase.h"
#include "inet/linklayer/contract/IMACProtocol.h"
using namespace inet;
namespace inet { } // namespace inet
class INET_API MyMac : public MACProtocolBase, public IMACProtocol
{
public:
MyMac();
virtual ~MyMac();
virtual void initialize(int stage) override;
};
#endif /* __INET_MYMAC_H */
MyMac.cc
#include "MyMac.h"
using namespace inet;
namespace inet {} // namespace inet
Define_Module(MyMac);
MyMac::MyMac() {}
MyMac::~MyMac() {}
void MyMac::initialize(int stage)
{
MACProtocolBase::initialize(stage);
}
答案 0 :(得分:0)
是的,可以在INET
目录之外准备一个项目。你应该:
OMNeT++
项目,然后转到其属性并选择inet
项目为Project References
。MyMac.ned
,MyMac.h
和MyMac.cc
移至新项目中。C++
文件:代码必须在命名空间inet
内,所有继承的纯虚方法都必须在您的代码中重写,{{1} }可能被删除。 INET_API
文件中为C ++类添加命名空间。更正代码:
MyMac.h:
NED
MyMac.cc:
#ifndef __INET_MYMAC_H
#define __INET_MYMAC_H
#include "inet/linklayer/base/MACProtocolBase.h"
#include "inet/linklayer/contract/IMACProtocol.h"
namespace inet {
class MyMac : public MACProtocolBase, public IMACProtocol
{
public:
MyMac();
virtual ~MyMac();
virtual void initialize(int stage) override;
protected:
virtual void handleUpperPacket(cPacket *packet) override ;
virtual void handleLowerPacket(cPacket *packet) override;
virtual bool isUpperMessage(cMessage *message) override;
virtual bool isLowerMessage(cMessage *message) override ;
virtual InterfaceEntry *createInterfaceEntry() override;
};
} // namespace inet
#endif /* __INET_MYMAC_H */
MyMac.ned:
#include "MyMac.h"
namespace inet {
Define_Module(MyMac);
MyMac::MyMac() {
}
MyMac::~MyMac() {
}
void MyMac::initialize(int stage) {
MACProtocolBase::initialize(stage);
}
void MyMac::handleUpperPacket(cPacket *packet) {
}
void MyMac::handleLowerPacket(cPacket *packet) {
}
bool MyMac::isUpperMessage(cMessage *message) {
}
bool MyMac::isLowerMessage(cMessage *message) {
}
InterfaceEntry *MyMac::createInterfaceEntry() {
}
} // namespace inet