14.2.6 Numeric promotions
来源:互联网 发布:通常端口号 编辑:程序博客网 时间:2024/05/17 10:39
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.
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.
- 14.2.6 Numeric promotions
- 14.2.6.1 Unary numeric promotions
- 14.2.6.2 Binary numeric promotions
- A - Promotions
- Promotions Gym
- Promotions Gym
- 关于Integral Promotions
- 整型提升(integral promotions)
- LA 7324 Promotions(bitset)
- UVALive 7272 Promotions
- Numeric 数据类型
- numeric questions
- STL--numeric
- DECIMAL NUMERIC
- Numeric Keypad
- Numeric Validation
- Numeric Keypad
- Numeric Keypad
- 14.2.1 Operator precedence and associativity
- 14.2.2 Operator overloading
- 14.2.3 Unary operator overload resolution
- 14.2.4 Binary operator overload resolution
- 14.2.5 Candidate user-defined operators
- 14.2.6 Numeric promotions
- 14.2.6.1 Unary numeric promotions
- 14.2.6.2 Binary numeric promotions
- 14.3 Member lookup
- 14.3.1 Base types
- java与oracle的接口
- 编译内核全过程(kernel2.6.XX)
- Linux启动全线提速法
- 我要改变自已