char ToChar(int val)
{
if(static_cast<unsigned>(val) <= 255) // better to use std::numeric_limits<unsigned char>::max() instead of 255
{
return static_cast<char>(val);
}
else
{
throw "trying to convert int to char with loosing of data"; // better to throw some another exception from the lib #include <stdexcept>
}
}