What is the difference between :
double x = 10.3;
int y;
y = (int) x; // c-like cast notation
And :
double x = 10.3;
int y;
y = reinterpret_cast<int>(x)
What is the difference between :
double x = 10.3;
int y;
y = (int) x; // c-like cast notation
And :
double x = 10.3;
int y;
y = reinterpret_cast<int>(x)
A C-style cast can be any of the following types of casts:
const_cast
static_cast
static_cast
followed by a const_cast
reinterpret_cast
reinterpret_cast
followed by a const_cast
the first one from that list that can be done is the what the C-style cast will perform (from C++03 5.4: "Explicit type conversion (cast notation)"
So for your example:
double x = 10.3;
int y;
y = (int) x;
the type of cast used would be a static_cast
.
And y = reinterpret_cast<int>(x);
won't compile.