OMNET++总是跳出Redefine HandleMessage()的错误

english100101992 2014-06-07 04:12:07
#include <stdio.h>
#include <string.h>
#include <omnetpp.h>
#include <myMessage_m.h>


class Txc10 : public cSimpleModule
{
protected:
virtual void forwardMessage(myMessage *msg);
virtual void initialize();
virtual void handleMessage(myMessage *msg);
};

Define_Module(Txc10);

void Txc10::initialize()
{
if (getIndex()==0)
{
// Boot the process scheduling the initial message as a self-message.
char msgname[20];
sprintf(msgname, "user-%d", getIndex());
myMessage *msg = new myMessage(msgname);
scheduleAt(0.0, msg);
}
}

void Txc10::handleMessage(myMessage *msg)
{
myMessage *ttmsg = check_and_cast<myMessage *>(msg);

if (getIndex()==3)
{
// Message arrived.
EV << "消息 " << ttmsg << " 到达.\n";
delete ttmsg;
}
else
{
// We need to forward the message.
forwardMessage(ttmsg);
}
}

void Txc10::forwardMessage(myMessage *msg)
{
// In this example, we just pick a random gate to send it on.
// We draw a random number between 0 and the size of gate `out[]'.
int n = gateSize("out");
int k = intuniform(0,n-1);

EV << "Forwarding message " << msg << " on port out[" << k << "]\n";
send(msg, "out", k);
}

...全文
331 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jinxiaodou 2014-12-24
  • 打赏
  • 举报
回复
是哪里出错了呢?
jinxiaodou 2014-12-24
  • 打赏
  • 举报
回复
是哪里出错了呢?
english100101992 2014-06-07
  • 打赏
  • 举报
回复
我擦,刚发完帖子就想到是哪里错了

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧