In Stroustrup's "The C++ Programming Language", exercise 6 of 5.9, I'm to pass an unsigned character and a signed character as arguments for f(char), g(char&) and h(const char&). Here is what I have:
void f(char c){}
void g(char& c){}
void h(constchar& c){}
int main()
{
unsignedchar uc;
f(uc); // OK
// g(uc); // error C2664: 'g' : cannot convert parameter 1 from '
// unsigned char' to 'char &'
// Explanation: The initializer of a "plain" T& must be an
// rvalue of type T. uc is a rvalue but its type is
// "unsigned char" whereas g()'s type is "char"
h(uc); // OK, const T& may take a different type.
signedchar sc;
f(sc); // OK
// g(sc); // error C2664: 'g' : cannot convert parameter 1 from
// 'signed char' to 'char &'
// Explanation: The initializer of a "plain" T& must be an
// rvaule of type T. sc is a rvalue but its type is
// "signed char" whereas g()'s type is "char"
h(sc); // // OK, const T& may take a different type.
return 0;
}
In my implementation, char *is* a signed char -- i.e.,
it's range is -128 to 127. So why does g(sc) above fail? Is type checking
of references so strict that it ignores the implementation of char?