Reputation: 3
I want to pass a variable of type MyPacket to handleMessage it gives error.
packet MyPacket { string msg; int srcAddress; int destAddress; };
Upvotes: 0
Views: 385
Reputation: 7002
Your MyPacket
will be converted into a C++ class MyPacket
which inhertis from cPacket
. And cPacket
inherits from cMessage
so it will be handled by handleMessage
. However, in handleMessage
you have to recognize and cast your packet, for example this way:
void YourSimpleModule::handleMessage(cMessage *msg) {
MyPacket * packet = dynamic_cast<MyPacket*> (msg);
if (packet != nullptr) {
// it is MyPacket
} else {
// other message
}
Upvotes: 2