void f(char){} void f(signed char){} void f(unsigned char){} int main(){}
同一程序的wchar_t版本不会:
void f(wchar_t){} void f(signed wchar_t){} void f(unsigned wchar_t){} int main(){}
错误:重新定义’void f(wchar_t)’
void f(签名的wchar_t){}
似乎wchar_t是无符号的.
为什么重载不一致?
解决方法
[basic.fundamental] / 1
[…] Plain
char
,signed char
,andunsigned char
are three distinct types,
collectively called narrow character types. […]
wchar_t也是一种不同的类型,但它不能使用signed或unsigned进行限定,只能与标准整数类型一起使用.
[dcl.type] / 2
As a general rule,at most one type-specifier is allowed in
the complete decl-specifier-seq of a declaration or in a
type-specifier-seq or trailing-type-specifier-seq. The only exceptions
to this rule are the following:[…]
signed
orunsigned
can be combined withchar
,long
,short
,orint
.
[dcl.type.simple] / 2
[…] Table 9 summarizes the valid combinations of simple-type-specifiers and the types they specify.
wchar_t的签名是实现定义的:
[basic.fundamental] / 5
[…] Type
wchar_t
shall have the same size,signedness,and alignment requirements (3.11) as one of the other integral types,called its underlying type.