如何在 omnet++6 中从另一条消息继承一条消息而不会出现错误?
How can I inherit a message from another message in omnet++6 without getting an error?
我有一条来自 cPacket 的消息(myJob):
packet MyJob extends omnetpp::cPacket
{
int someField;
string anotherField;
double arrayField1[];
double arrayField2[10];
}
我的目标是创建另一条从 MyJob 派生的消息。为此,我从 Project->New->Messafe Definition(msg)
I select "Message that subclasses from a message defined in another .msg file"
选项创建了另一条消息。我在 return:
中得到了这个
cplusplus {{
#include "SomeMessage_m.h"
}}
packet SomeMessage;
packet MyMessage extends SomeMessage {
int someField;
}
我尝试编译时出现错误,但这是可以理解的,因为没有 SomeMessage
,没关系。比起我把 SomeMessage
s 改成 MyJob
s
cplusplus {{
#include "MyJob_m.h"
}}
packet MyJob;
//
// TODO generated message class
//
packet MyMessage extends MyJob {
int someField;
}
但我得到了与SomeMessage
相同的错误。
'MyMessage': unknown base class 'MyJob' MyMessage.msg
MyMessage: base class is not a packet (must be derived from omnetpp::cPacket)
Type declarations are not needed with imports, try invoking the message compiler in legacy (4.x) mode using the --msg4 option
如何从另一个继承消息?
OMNeT++ 6.0 中数据包的正确定义应该如下所示:
// myjob.msg
packet MyJob {
int someField;
string anotherField;
double arrayField1[];
double arrayField2[10];
}
要创建从上述消息派生的数据包,应该这样写:
// mymessage.msg
import MyJob;
packet MyMessage extends MyJob {
int someField;
}
请注意,根据 OMNeT++ 模拟手册,基本消息的文件名必须与 import
的参数相匹配:
The import’s parameter is interpreted as a relative file path (by replacing dots with slashes,
and appending .msg), which is searched for in folders listed in the message import path, much
like C/C++ include files are searched for in the compiler’s include path
我有一条来自 cPacket 的消息(myJob):
packet MyJob extends omnetpp::cPacket
{
int someField;
string anotherField;
double arrayField1[];
double arrayField2[10];
}
我的目标是创建另一条从 MyJob 派生的消息。为此,我从 Project->New->Messafe Definition(msg)
I select "Message that subclasses from a message defined in another .msg file"
选项创建了另一条消息。我在 return:
cplusplus {{
#include "SomeMessage_m.h"
}}
packet SomeMessage;
packet MyMessage extends SomeMessage {
int someField;
}
我尝试编译时出现错误,但这是可以理解的,因为没有 SomeMessage
,没关系。比起我把 SomeMessage
s 改成 MyJob
s
cplusplus {{
#include "MyJob_m.h"
}}
packet MyJob;
//
// TODO generated message class
//
packet MyMessage extends MyJob {
int someField;
}
但我得到了与SomeMessage
相同的错误。
'MyMessage': unknown base class 'MyJob' MyMessage.msg
MyMessage: base class is not a packet (must be derived from omnetpp::cPacket)
Type declarations are not needed with imports, try invoking the message compiler in legacy (4.x) mode using the --msg4 option
如何从另一个继承消息?
OMNeT++ 6.0 中数据包的正确定义应该如下所示:
// myjob.msg
packet MyJob {
int someField;
string anotherField;
double arrayField1[];
double arrayField2[10];
}
要创建从上述消息派生的数据包,应该这样写:
// mymessage.msg
import MyJob;
packet MyMessage extends MyJob {
int someField;
}
请注意,根据 OMNeT++ 模拟手册,基本消息的文件名必须与 import
的参数相匹配:
The import’s parameter is interpreted as a relative file path (by replacing dots with slashes, and appending .msg), which is searched for in folders listed in the message import path, much like C/C++ include files are searched for in the compiler’s include path