Click to See Complete Forum and Search --> : casting


Grace
October 28th, 1999, 06:22 PM
In the past year or so, I've seen casting like:

CObj* x = static_cast<CObj*> (y);




Is there any advantages of using static_cast instead of the good old casting like:

CObj* x = (CObj*)y





-= hm... =-
Grace

JohnCz
October 28th, 1999, 09:01 PM
Short answer:
A static_cast is stricter about the conversions it allows.

For example: unlike the old C/C++ style cast (your example 2), it won't convert function pointers unless it can convert all the arguments and return types.
However, that static_cast does not perform a run-time check.


I don't do it for ratings, but appreciation is always in style.
Good luck in your journey in a C++ land.