OMNET++中如何通过单个emit()传递多个变量?
根据 OMNET++ 模拟手册,emit() 可以携带的类型是:“值可以是 bool、long、double、simtime_t、const char * 或 (const) cObject * 类型。可以强制转换其他类型转换为这些类型之一,或包装到从 cObject 子类化的对象中。”
因此,要通过单个 emit() 传递多个变量,必须使用 cObject。手册对此的解决方案是创建一个由 cObject 驱动的类来保存值并将其传递给 emit()。
class cRawTableData : public cObject, noncopyable
{
public:
unsigned int sVehicleID;
double sPositionX;
double sPositionY;
double sSpeed;
};
if (hasListeners(rawTableSignal)){
cRawTableData tmp;
tmp.sVehicleID=senderId;
tmp.sPositionX=senderPOx;
tmp.sPositionY=senderPOy;
tmp.sSpeed=senderSpeed;
emit(rawTableSignal, &tmp);
}
但是,当我运行模拟时,出现此错误:
omnetpp::VectorRecorder: Cannot convert cObject* to double
我做错了什么?谢谢你的帮助
According to OMNET++ Simulation Manual the types can be carried by emit() are, "The value can be of type bool, long, double, simtime_t, const char * , or (const) cObject * . Other types can be cast into one of these types, or wrapped into an object subclassed from cObject."
So to pass multiple vairables through single emit(), cObject must be used. The Manual's solution for this is to create a class driven from cObject to hold the values and pass it to the emit().
class cRawTableData : public cObject, noncopyable
{
public:
unsigned int sVehicleID;
double sPositionX;
double sPositionY;
double sSpeed;
};
if (hasListeners(rawTableSignal)){
cRawTableData tmp;
tmp.sVehicleID=senderId;
tmp.sPositionX=senderPOx;
tmp.sPositionY=senderPOy;
tmp.sSpeed=senderSpeed;
emit(rawTableSignal, &tmp);
}
However, when I run the simulation I get this error:
omnetpp::VectorRecorder: Cannot convert cObject* to double
What is that I am doing wrong? thank you for the help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论