14.2.6 Numeric promotions

王朝other·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

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.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航