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:
committed by
Christopher McCormack
parent
f683a487d1
commit
445f8ac27e
@ -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;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user