Help !!! Transform Message class to cPacket class.

27 views
Skip to first unread message

tung_dhqn

unread,
Jul 23, 2014, 9:13:17 AM7/23/14
to omn...@googlegroups.com
Hello !!!
I transform msg format to cpacket format by "check_and_cast<cPacket>(msg)->hasBitError"  but i don't, Omnet++4.1 inform error. So, Anybody know do it ? Please me. 

Ivo Calado

unread,
Jul 23, 2014, 9:15:43 AM7/23/14
to omn...@googlegroups.com

On Wed, Jul 23, 2014 at 10:13 AM, tung_dhqn <tung...@gmail.com> wrote:
check_and_cast<cPacket>(msg)->hasBitError

Try this => check_and_cast<cPacket*>(msg)->hasBitError()


--
Ivo Calado

Quidquid latine dictum sit, altum viditur

Putt's Law:
       Technology is dominated by two types of people:
               Those who understand what they do not manage.
               Those who manage what they do not understand.

tung_dhqn

unread,
Jul 23, 2014, 9:44:01 AM7/23/14
to omn...@googlegroups.com, ivo.c...@ee.ufcg.edu.br
Sorry. I didn't correctly write format , lack * sign. Do you have different way ?

Vào 20:15:43 UTC+7 Thứ tư, ngày 23 tháng bảy năm 2014, Ivo Calado đã viết:

Alfonso Ariza Quintana

unread,
Jul 23, 2014, 10:15:44 AM7/23/14
to omn...@googlegroups.com

You should read in the manual the difference between cPacket and cMessage

--
You received this message because you are subscribed to the Google Groups "omnetpp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

tung_dhqn

unread,
Jul 23, 2014, 10:58:18 AM7/23/14
to omn...@googlegroups.com, aari...@hotmail.com
Hi Alfonso Ariza Quintana !
Do you have idea ? I have modified Physic.cc successfully !. Hello Message sent ! But. Nodes don't exam this msg (it does not "hasBitError" function) so I need transform msg format to packet format. do you think ???

Vào 21:15:44 UTC+7 Thứ tư, ngày 23 tháng bảy năm 2014, Alfonso Ariza Quintana đã viết:

Alfonso Ariza Quintana

unread,
Jul 23, 2014, 12:44:11 PM7/23/14
to omn...@googlegroups.com

It is a problem how the message has created, if the message was created like cPacket you can convert, but if the message was originally created like cMessage, you will never convert to cPacket and if you force the conversion with static_cast, the code will access to incorrect areas because cMessage doesn’t have error data.

 

It is a basic c++ inherence rule.

Check_and_cast does a dynamic_cast, like the result of the conversion is null it throws an error

 

An alternative is

 

cPacket pkt = dynamic_cast<cPacket*>(msg);

if (pk)

{

// it is a packet

       If (pk->hasBitError())

              …..

}

else

{

// it isn’t a packet, is it a timer?

    ….

Reply all
Reply to author
Forward
0 new messages