Show: Delphi C++
Display Preferences

UCSC -- Use C++ Style Casts

From RAD Studio
Jump to: navigation, search

Go Up to C++ Audits

Description

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.

Incorrect

 return (Cat*)myAnimalPtr;

Correct

 return dynamic_cast<Cat*>(myAnimalPtr);

See Also

Personal tools
RAD Studio 10.2 Tokyo
In other languages
Previous Versions
Assistance