UCSC -- Use C++ Style Casts

From RAD Studio
Jump to: navigation, search

Go Up to C++ Audits


Audit checks for C-style casts, which should be avoided. There are several casting operators specific to the C++ language, which should be used instead. These operators are intended to remove some of the ambiguity and danger inherent in C-style casting. These operators are:

Use the C++ operators listed here, instead of C-style casting. However, avoid using const_cast and reinterpret_cast, if possible. These operators have the same dangers as C-style casts, but they are still necessary in order to completely replace C-style casts.


 return (Cat*)myAnimalPtr;


 return dynamic_cast<Cat*>(myAnimalPtr);

See Also