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
Printable View
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
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.