如何将标准容器作为字段添加到 OMNet++ 消息中?



我正在尝试创建一个简单的消息定义,其中包含使用std::vector实现的字段。 根据OMNet++ 5.5手册第6章第8.1节,这似乎很简单。

但是,我使用的是OMNet++ 6.0pre6:我无法弄清楚正确的方法是什么,因为手册已经过时了1,并且更改在nedxml更改日志中非常肤浅地引用。

消息定义可以归结为手册中的确切示例,但在这种情况下,它是一个message而不是packet(两者都会产生相同的错误(:

cplusplus {{
#include <vector>
typedef std::vector<int> IntVector;
}}
class noncobject IntVector;
message SimpleMsg {
int this_thing;
int that_thing;
IntVector these_things;
}

消息到C++转译器opp_msgtool提供了以下错误:

SimpleMsg.msg:6: Error: Type declarations are not needed with imports, try invoking the message compiler in legacy (4.x) mode using the --msg4 option
SimpleMsg.msg:11: Error: unknown type 'IntVector' for field 'these_things' in 'SimpleMsg'

认为导入不需要类型声明可能是从OMNet 5.x到6.x的更改的简单摘要,我继续删除class noncobject IntVector。虽然它删除了第一个错误,但它仍然产生Error: unknown type 'IntVector' for field 'these_things' in 'SimpleMsg'

想法?建议?要上课吗?

编辑:值得注意的是,nedxml更新日志中有一些注释提到了4.0-5.x和6.0之间的更改,但理想情况下如何使用它不太清楚。


1当然不完全适用于OMNet++ 6.0至少。

它应该是这样的:

cplusplus {{
#include <vector>
typedef std::vector<int> IntVector;
}}
class IntVector {
@existingClass;
}
message SimpleMsg {
int this_thing;
int that_thing;
IntVector these_things;
}

另一种"解决方案"是强制消息编译器进入 4.x 兼容(旧模式(。只需在 makefrag 文件中添加以下行即可

MSGC:=$(MSGC) --msg4

但是,迟早你应该转换你的代码。如果您希望代码同时使用 OMNeT++ 5.5 和 6.0 进行编译,那么绝对应该显式指定 MSG 编译器版本。兼容 4.x 或 6.x。

最新更新