[Omnetpp-l] cannot cast cMessage to cPacket

Showing 1-5 of 5 messages
[Omnetpp-l] cannot cast cMessage to cPacket Vitali Anselm 4/7/09 1:42 AM
Hello,

I use some functions like getByteLength() in my handleMessage(cMessage *msg)  function, so I decided to cast msg to cPacket to be able to use these functions. For this I wrote the following code:

cPacket *tempPtr = check_and_cast<cPacket *>(msg);

and then I use tempPtr at places, where the cPacket functions are called.

When I compile all, there is no errors, but when I want to run TKenv there is
 the following error:

 Error in module(.....):
 check_and_cast():cannot cast (cMessage*).......[0].per_second_timer to type
 "P7cPacket".

per_second_timer is declared as cMessage:

per_second_timer = new cMessage("per_second_timer");
        scheduleAt(simTime(), per_second_timer);

Can you help me?

regards,

Vitali
____________________________________________________________________
Psssst! Schon vom neuen WEB.DE MultiMessenger gehört?
Der kann`s mit allen: http://www.produkte.web.de/messenger/?did=3123

_______________________________________________
Omnetpp-l mailing list
Omne...@omnetpp.org
http://lists.omnetpp.org/mailman/listinfo/omnetpp-l

Re: [Omnetpp-l] cannot cast cMessage to cPacket Ahmed Ayadi 4/7/09 1:35 PM
Hello,

try to use cPacket * PK(cMessage  *) to cast cMessage to cPacket.

regards,
--
Ahmed
Re: [Omnetpp-l] cannot cast cMessage to cPacket Alfonso Ariza Quintana 4/9/09 7:33 AM

it's inherit problem

cPacket is a descendant of cMessage

if you create a

cPacket *pkt = new cPacket();
cMessage *msg = pkt; // Valid   cPacket is a descendant of cMessage
cPacket *pkt2 = dynamic_cast<cPacket*>(msg);


 pkt2 <> null because msg containt a cPacket


 but if you do

cMessage *msg = new cMessage();
cPacket *pkt2 = dynamic_cast<cPacket*>(msg);

pkt2 = NULL because msg not contain a cPacket, contain a cMessage


> Date: Tue, 7 Apr 2009 10:42:04 +0200
> From: Vitali...@web.de
> To: omne...@omnetpp.org
> Subject: [Omnetpp-l] cannot cast cMessage to cPacket
Haz búsquedas desde Live Search y ayuda a 22 niños de un orfanato en Nepal ¡Colabora!
Re: [Omnetpp-l] cannot cast cMessage to cPacket ktn varma 2/18/13 9:22 PM
So, can someone help me with a solution to this problem...
Re: [Omnetpp-l] cannot cast cMessage to cPacket Rudolf Hornig 2/19/13 2:32 AM
This is a 4 year old topic. If you are interested in the solution:

an object with dynamic type cMessage cannot be cast to cPacket. That's why the code has failed on check_and_cast