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

Tho*_*hor 1 c++ omnet++

我正在尝试创建一个简单的消息定义,其中包含使用std::vector. 根据OMNet++ 5.5 手册 ch。6 秒。8.1,这看似简单。

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

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

cplusplus {{
#include <vector>
typedef std::vector<int> IntVector;
}}

class noncobject IntVector;

message SimpleMsg {
    int this_thing;
    int that_thing;
    IntVector these_things;
}
Run Code Online (Sandbox Code Playgroud)

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

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'

Run Code Online (Sandbox Code Playgroud)

认为导入不需要类型声明可能是从 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。

Rud*_*udi 5

它应该是这样的:

cplusplus {{
#include <vector>
typedef std::vector<int> IntVector;
}}

class IntVector {
    @existingClass;
}

message SimpleMsg {
    int this_thing;
    int that_thing;
    IntVector these_things;
}
Run Code Online (Sandbox Code Playgroud)

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

MSGC:=$(MSGC) --msg4
Run Code Online (Sandbox Code Playgroud)

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