问题
I'm trying to create a simple message definition that contains a field implemented using std::vector
.
Per the OMNet++ 5.5 manual ch. 6 sec. 8.1, this is seemingly straightforward.
However, I'm using OMNet++ 6.0pre6: I can't figure out what the correct way of doing this is, as the manual is out of date1, and the changes are very superficially referred to in the nedxml
changelog.
The message definition can be boiled down to the exact example in the manual, but in this case it is a message
rather than a packet
(either yields same error):
cplusplus {{
#include <vector>
typedef std::vector<int> IntVector;
}}
class noncobject IntVector;
message SimpleMsg {
int this_thing;
int that_thing;
IntVector these_things;
}
The following errors were provided by opp_msgtool
, the messages-to-C++ transpiler:
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'
Thinking type declarations are not needed with imports could be the simple summary of the changes from OMNet 5.x to 6.x, I proceeded to remove class noncobject IntVector
. While it removes the first error, it still yields Error: unknown type 'IntVector' for field 'these_things' in 'SimpleMsg'
.
Ideas? Suggestions? Lessons to be had?
EDIT: Notably found that there are some notes in the nedxml changelog referring to changes between 4.0-5.x and 6.0, but how to ideally use it is less clear.
1 Certainly not wholly applicable to OMNet++ 6.0 at the very least.
回答1:
It should be something like this:
cplusplus {{
#include <vector>
typedef std::vector<int> IntVector;
}}
class IntVector {
@existingClass;
}
message SimpleMsg {
int this_thing;
int that_thing;
IntVector these_things;
}
An alternate 'solution' is to force the message compiler into 4.x compatible (old mode). Just add the following line in a makefrag file
MSGC:=$(MSGC) --msg4
However, sooner or later you should convert your code. If you want your code to compile with both OMNeT++ 5.5 and 6.0 then you should definitely specify the MSG compiler version explicitly. Either to be 4.x or 6.x compatible.
来源:https://stackoverflow.com/questions/59786184/how-can-a-standard-container-be-added-as-a-field-to-an-omnet-message