我知道,这可能要问很多,但是谁能帮助我调试此代码:
#include <stdio.h>
#include <string.h>
#include <omnetpp.h>
using namespace omnetpp;
class Node : public cSimpleModule
{
private:
cMessage *out_msg;
long no_sent = 0;
long no_rcvd = 0;
cOutVector rcvdRecord;
cLongHistogram Statistics;
public:
Node();
virtual ~Node();
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
virtual void finish() override;
};
Define_Module(Node);
Node::Node()
{
out_msg = nullptr;
}
Node::~Node()
{
delete out_msg;
}
void Node::initialize()
{
out_msg = nullptr;
if (strcmp("sender", getName()) == 0) {
EV << "Scheduling first send to t=5.0s\n";
scheduleAt(5.0, out_msg);
out_msg = new cMessage("Sending Message");
}
}
void Node::handleMessage(cMessage *msg)
{
if (msg == out_msg) {
EV << "Sending message to receiver\n";
send(out_msg, "out");
out_msg = nullptr;
no_sent++;
simtime_t delay = par("delayTime");
scheduleAt(simTime() + delay, out_msg);
}
else {
out_msg = msg;
no_rcvd++;
rcvdRecord.record(out_msg);
Statistics.collect(out_msg); //what's going on here ?
}
}
void Node::finish()
{
EV << "Sent: " << no_sent << endl;
EV << "Received: " << no_rcvd << endl;
EV << "Messages sent, mean: " << Statistics.getMean() << endl;
EV << "Messages sent, standard deviation: " << Statistics.getStddev() << endl;
EV << "Messages sent, variance: " << Statistics.getVariance() << endl;
recordScalar("#sent", no_sent);
recordScalar("#received", no_rcvd);
Statistics.recordAs("Message Statistics");
}
我收到以下错误消息:
Exercise2.cc:66:38:错误:没有匹配的函数可调用
'omnetpp :: cOutVector :: record(omnetpp :: cMessage *&)'
Exercise2.cc:67:39:错误:没有匹配的函数可以调用
'omnetpp :: cLongHistogram :: collect(omnetpp :: cMessage *&)'
所以我真的不知道这应该告诉我什么。这些内置函数不是分别属于
cOutVector
或cLongHistogram
类的一部分吗? 最佳答案
这些内置函数不是cOutVector
的一部分吗?
cLongHistogram
类?
他们不是。好吧,cOutVector
确实有一个名为record
的成员函数,它只是不能将cMessage *
作为参数,所以不存在您要使用的特定函数重载。与cLongHistogram
和collect
相同。
只需看一下documentation:
一个cOutVector对象可以将双精度数写入输出矢量文件...
而且,顺便说一句,您期望看到“消息直方图”到底是什么? :D This comic浮现在我的脑海...
要记录消息(不记录到cOutVector
中),可以启用event logging。可以在IDE的“序列表”工具中可视化生成的文件,请参见:https://docs.omnetpp.org/tutorials/tictoc/part2/#25-visualizing-on-a-sequence-chart
关于c++ - 示例:在OMNeT++中进行调试,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49958505/