19.8.3. Why Not Use C-Style Casts?

[ fromfile: types.xml id: whynotC-style ]

        Apple apple;
        Orange* orangeP;
        // other processing steps ...
        orangeP = (Orange*) &apple;
        orangeP->peel();
      
[Note]Note

ANSI typecasts are preferred over the old style casts.

  • They are safer.

  • They are easy to locate in code if modifications are required.

  • They clearly convey the intention of the programmer.

  • They clearly distinguish between portable and nonportable casts.