Reputation: 1961
When doing a type conversion from a variable to a reference, like:
float f = 1.0f;
int a = (int&) f;
std::cout << a;
Why do I get the actual bit-representation of the float value (and not the numeric value).
Upvotes: 0
Views: 514
Reputation: 132994
Your code is undefined behavior, technically speaking. Your C-style cast does a reinterpret_cast
which isn't defined for convering a float
lvalue to int&
. Maybe you just wanted to cast to an int
?
Upvotes: 4
Reputation: 2640
Because reference in C++ means "another name for". So when you cast something to a reference you just give it another name, and not perform a value conversion from floats to integers.
Upvotes: 1
Reputation: 46183
Why are you converting a variable to a reference and then storing it in a variable?
Upvotes: 0