No, this is not legal.
Converting an explicit type to a function style requires a simple type specifier, followed by a parenthesized list of expressions. (ยง5.2.3) unsigned char not a type specifier; this is due to a question raised by James .
Obviously, if unsigned char was a simple type specifier, that would be legal. A workaround should be to use std::identity :
template <typename T> struct identity { typedef T type; };
And then:
int a = std::identity<unsigned char>::type('0');
std::identity<unsigned char>::type is a specifier of a simple type, and its type is just the type of the template parameter.
Of course, you get two-for-one with static_cast . In any case, this is the preferred casting method.
GManNickG
source share