I am new to explicit casts in C++. I thought that static_cast was way more restrictive than reinterpret_cast. However, I have a function where static_cast gives me the desired result and reinterpret_cast tells me that my conversion is invalid. Why is this happening?
void from_int(int x)
{
if (x < 32 || x > 126)
std::cout << "char: Non displayable" << std::endl;
std::cout << "char: '" << reinterpret_cast<char>(x) << "'" << std::endl;
std::cout << "int: " << x << std::endl;
std::cout << "float: " << x << ".0f" << std::endl;
std::cout << "double: " << x << ".0" << std::endl;
}