seems we can do with static_cast in Bye::castFrom etc…

Hi all

While going thru Bye.h

inline Bye & Bye::castFrom (Packet & packet)
{ return dynamic_cast (packet); }
I think static_cast would be a better  choice here…

The reason is that as the compiler can see the line
class Bye : public Packet

the static cast should be safe… ( We don’t need the heavy duty dynamic_cast here )

I mean here it may not matter much but if some cycles are saved the better…. and in other places it might make some difference.

Also dynamic_cast implies RTTI must be used and generated… here anway it is as Packet::copy is the virtual constructor stuff… but other places it could matter ;-)

I accept that safety offered by dynamic_cast is good  and yes “Early optimization is the root of all evil” but still

here are my two cents … ;-)

Would you like to post a relpy?


This post starts a thread.
Follow-ups:
Re: seems we can do with static_cast in Bye::castFrom etc…
I think I was a little sleepy when I wrote that.... Now as I think I am wide awake ;-) , as it can not be guaranteed here by design ( (more...)