Friday, 30 August 2013

How to use reinterpret_cast in C++?

How to use reinterpret_cast in C++?

I know the reinterpret_cast in C++ can be used in this way:
float a = 0;
int b = *reinterpret_cast<int*>(&a);
But why cannot cast it directly?
float a = 0;
int b = reinterpret_cast<int>(a);
error: invalid cast from type 'float' to type 'int'

No comments:

Post a Comment