14.2.6 Numeric promotions

博客介绍了数值提升,它是对预定义一元和二元数值运算符操作数自动进行隐式转换的效果,由运算符重载解析产生,不影响用户定义运算符。还通过二元 * 运算符示例,说明重载解析规则会选择能对操作数类型进行隐式转换的首个运算符。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

This clause is informative.
Numeric promotion consists of automatically performing certain implicit
conversions of the operands of the
predefined unary and binary numeric operators. Numeric promotion is not a
distinct mechanism, but rather
an effect of applying overload resolution to the predefined operators.
Numeric promotion specifically does
not affect evaluation of user-defined operators, although user-defined
operators can be implemented to
exhibit similar effects.
As an example of numeric promotion, consider the predefined implementations
of the binary * operator:
int operator *(int x, int y);
uint operator *(uint x, uint y);
long operator *(long x, long y);
ulong operator *(ulong x, ulong y);
float operator *(float x, float y);
double operator *(double x, double y);
decimal operator *(decimal x, decimal y);
When overload resolution rules (?4.4.2) are applied to this set of
operators, the effect is to select the first of
the operators for which implicit conversions exist from the operand types.
[Example: For example, for the
operation b * s, where b is a byte and s is a short, overload resolution
selects operator *(int, int)
as the best operator. Thus, the effect is that b and s are converted to
int, and the type of the result is int.
Likewise, for the operation i * d, where i is an int and d is a double,
overload resolution selects
operator *(double, double) as the best operator. end example]
End of informative text.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值