强制转换运算符Cast Operators

在特定情况下,类型强制转换提供了用于显式转换对象类型的方法。A type cast provides a method for explicit conversion of the type of an object in a specific situation.

语法Syntax

cast-expressioncast-expression:
unary-expressionunary-expression

( type-name ) cast-expression( type-name ) cast-expression

在进行类型强制转换后,编译器将 cast-expression 视为类型 type-name。The compiler treats cast-expression as type type-name after a type cast has been made. 强制转换可用于在任意标量类型的对象与任何其他标量类型之间进行来回转换。Casts can be used to convert objects of any scalar type to or from any other scalar type. 显式类型强制转换受到确定隐式转换效果的相同规则的约束,如赋值转换中所述。Explicit type casts are constrained by the same rules that determine the effects of implicit conversions, discussed in Assignment Conversions. 有关强制转换的其他约束可能来源于特定类型的实际大小或表示形式。Additional restraints on casts may result from the actual sizes or representation of specific types. 有关整型类型的实际大小的信息,请参阅基本类型的存储See Storage of Basic Types for information on actual sizes of integral types. 有关类型强制转换的详细信息,请参阅类型强制转换For more information on type casts, see Type-Cast Conversions.

另请参阅See Also

强制转换运算符:()Cast Operator: ()