error: invalid static_cast from type 'xxx*' to type 'yyy*'

error: invalid static_cast from type ‘xxx*’ to type ‘yyy*’

通常来说, static_cast 不适用于不同指针类型之间的转换, 因为它们是完全不同的两个类型. 如果
自己清楚自己在做什么, 通常对于不同指针类型的转换应该使用reinterpret_cast

C++标准如下:

3.9.1 Fundamental types [basic.fundamental]

1 Objects declared as characters char shall be large enough to store
any member of the implementation's basic character set. If a character from this
set is stored in a character object, the integral value of that character object
is equal to the value of the single character literal form of that character.

It is implementation-defined whether a char object can hold negative values.
Characters can be explicitly declared unsigned or signed. Plain char, signed
char, and unsigned char are three distinct types. A char, a signed char, and
an unsigned char occupy the same amount of storage and have the same alignment
requirements (basic.types); that is, they have the same object representation.
For character types, all bits of the object representation participate in the
value representation. For unsigned character types, all possible bit patterns
of the value representation represent numbers. These requirements do not hold
for other types. In any particular implementation, a plain char object can take
on either the same values as a signed char or an unsigned char; which one is
implementation-defined.

下面这个是摘自 Bjarne Stroustrup

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值