Item 9. New Cast Operators
There’s something sneaky and underhanded about old-style casts. Their syntax is such that they can often pass unnoticed in a section of code, but they can do terrible damage, like an unexpected sucker punch from a bully. Let’s clarify what we mean by “old-style” cast. Obviously, the original C syntax consisting of a parenthesized type applied to an expression is an old-style cast:
char *hopeItWorks = (char *)0x00ff0000; // old-style cast
C++ introduced another way of saying the same thing with the function-style cast syntax:
typedef char *PChar;hopeItWorks = PChar( 0x00ff0000 ); // function-style/old-style cast
A function-style cast may look more civilized than its dread ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access