Game Development Community

Generic C++/Torque pointer witchcraft question

by Gary "ChunkyKs" Briggs · in Torque Game Engine · 08/24/2006 (4:15 pm) · 3 replies

I'm not really much of a C++ guru, so this is probably a dumb question. But: Poking through code, I see this used everywhere:

mDataBlock = dynamic_cast<JMTorqueData*>(dptr);
Why is this better, worse, different from, or the same as:
mDatablock = (JMTorqueData *)dptr;

That whole dynamic_cast-angle-brackets thing versus the normal cast that I'm familiar with. What's the difference?

Gary (-;

#2
08/24/2006 (4:51 pm)
Definitely read Dreamer's link,
but the short answer is that the first example will only succeed if dptr does in fact point to a JMTorqueData,
whereas the second example succeeds even when it shouldn't.

if you *know* the pointer points to an object of the correct type,
then using the second approach is slightly faster.
#3
08/24/2006 (5:07 pm)
Huh, I didn't know that. Thank-you very much!

Gary (-;