Added ex C style Cast - important to recognize (#27371)

Additional note on how C-style casts are not recommended. Important for people to recognize when they come across, and modify if they wish.
This commit is contained in:
whoandrewis
2019-02-07 07:15:33 -08:00
committed by Christopher McCormack
parent f683a487d1
commit 445f8ac27e

View File

@ -70,12 +70,20 @@ void staticCastTest(float floatVal) {
std::cout << intVal << std::endl; std::cout << intVal << std::endl;
} }
//not recommended but important to recognize
void cStyleCastTest(float floatVal) {
// Convert the float into a double.
auto doubleVal = (double)(floatVal);
std::cout << doubleVal << std::endl;
}
int main() { int main() {
MyClassChild myClass; MyClassChild myClass;
reinterpretCastTest(&myClass); reinterpretCastTest(&myClass);
constCastTest(myClass); constCastTest(myClass);
dynamicCastTest(&myClass); dynamicCastTest(&myClass);
staticCastTest(10.5); staticCastTest(10.5);
cStyleCastTest(11.9);
return 0; return 0;
} }