问题描述
以下C ++程序可正确编译:
The following C++ program compiles without errors:
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)"
无效f(signed wchar_t){}
error: redefinition of ‘void f(wchar_t)’
void f(signed wchar_t){}
似乎wchar_t
是unsigned
.
为什么超载不一致?
It seems that wchar_t
is unsigned
.
Why is there an inconsistency in overloading?
推荐答案
char
都是不同的类型,可以重载
The char
s are all distinct types and can be overloaded
[基本原理]/1
wchar_t
也是一种独特的类型,但是不能用signed
或unsigned
限定,它们只能与标准整数类型一起使用.
wchar_t
is also a distinct type, but it cannot be qualified with signed
or unsigned
, which can only be used with the standard integer types.
[dcl.type]/2
[dcl.type] / 2
[...]
signed
或unsigned
可以与char
,long
,short
或int
组合.
signed
or unsigned
can be combined with char
, long
, short
, or int
.
[dcl.type.simple]/2
[dcl.type.simple] / 2
wchar_t
的签名是由实现定义的:
The signedness of wchar_t
is implementation defined:
[基本知识]/5
这篇关于为什么char不带符号或不带符号,而wchar_t是带符号的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!