Стандарт C++ 98 (1119566), страница 24
Текст из файла (страница 24)
The effect of such an explicit conversion is the same as performing the declaration and initialization and then using the temporary variable as the result of the conversion. The result is an lvalue if T is areference type (8.3.2), and an rvalue otherwise. The expression e is used as an lvalue if and only if theinitialization uses it as an lvalue.3Otherwise, the static_cast shall perform one of the conversions listed below. No other conversionshall be performed explicitly using a static_cast.4Any expression can be explicitly converted to type “cv void.” The expression value is discarded.
[Note:however, if the value is in a temporary variable (12.2), the destructor for that variable is not executed untilthe usual time, and the value of the variable is preserved for the purpose of executing the destructor. ] Thelvalue-to-rvalue (4.1), array-to-pointer (4.2), and function-to-pointer (4.3) standard conversions are notapplied to the expression.5An lvalue of type “cv1 B”, where B is a class type, can be cast to type “reference to cv2 D”, where D is aclass derived (clause 10) from B, if a valid standard conversion from “pointer to D” to “pointer to B” exists(4.10), cv2 is the same cv-qualification as, or greater cv-qualification than, cv1, and B is not a virtual baseclass of D. The result is an lvalue of type “cv2 D.” If the lvalue of type “cv1 B” is actually a sub-object ofan object of type D, the lvalue refers to the enclosing object of type D.
Otherwise, the result of the cast isundefined. [Example:struct B {};struct D : public B {};D d;B &br = d;static_cast<D&>(br);// produces lvalue to the original d object—end example]6The inverse of any standard conversion sequence (clause 4), other than the lvalue-to-rvalue (4.1), array-topointer (4.2), function-to-pointer (4.3), and boolean (4.12) conversions, can be performed explicitly usingstatic_cast subject to the restriction that the explicit conversion does not cast away constness (5.2.11),and the following additional rules for specific cases:72© ISO/IEC5 ExpressionsISO/IEC 14882:1998(E)5.2.9 Static cast7A value of integral type can be explicitly converted to an enumeration type.
The value is unchanged if theintegral value is within the range of the enumeration values (7.2). Otherwise, the resulting enumerationvalue is unspecified.8An rvalue of type “pointer to cv1 B”, where B is a class type, can be converted to an rvalue of type “pointerto cv2 D”, where D is a class derived (clause 10) from B, if a valid standard conversion from “pointer to D”to “pointer to B” exists (4.10), cv2 is the same cv-qualification as, or greater cv-qualification than, cv1, andB is not a virtual base class of D. The null pointer value (4.10) is converted to the null pointer value of thedestination type. If the rvalue of type “pointer to cv1 B” points to a B that is actually a sub-object of anobject of type D, the resulting pointer points to the enclosing object of type D.
Otherwise, the result of thecast is undefined.9An rvalue of type “pointer to member of D of type cv1 T” can be converted to an rvalue of type “pointer tomember of B of type cv2 T”, where B is a base class (clause 10) of D, if a valid standard conversion from“pointer to member of B of type T” to “pointer to member of D of type T” exists (4.11), and cv2 is the samecv-qualification as, or greater cv-qualification than, cv1.63) The null member pointer value (4.11) is converted to the null member pointer value of the destination type. If class B contains the original member, oris a base or derived class of the class containing the original member, the resulting pointer to memberpoints to the original member.
Otherwise, the result of the cast is undefined. [Note: although class B neednot contain the original member, the dynamic type of the object on which the pointer to member is dereferenced must contain the original member; see 5.5. ]10An rvalue of type “pointer to cv void” can be explicitly converted to a pointer to object type.
A value oftype pointer to object converted to “pointer to cv void” and back to the original pointer type will have itsoriginal value.5.2.10 Reinterpret cast[expr.reinterpret.cast]1The result of the expression reinterpret_cast<T>(v) is the result of converting the expression v totype T. If T is a reference type, the result is an lvalue; otherwise, the result is an rvalue and the lvalue-torvalue (4.1), array-to-pointer (4.2), and function-to-pointer (4.3) standard conversions are performed on thethe expression v. Types shall not be defined in a reinterpret_cast.
Conversions that can be performed explicitly using reinterpret_cast are listed below. No other conversion can be performedexplicitly using reinterpret_cast.2The reinterpret_cast operator shall not cast away constness. [Note: see 5.2.11 for the definition of‘‘casting away constness’’. Subject to the restrictions in this section, an expression may be cast to its owntype using a reinterpret_cast operator. ]3The mapping performed by reinterpret_cast is implementation-defined.
[Note: it might, or mightnot, produce a representation different from the original value. ]4A pointer can be explicitly converted to any integral type large enough to hold it. The mapping function isimplementation-defined [Note: it is intended to be unsurprising to those who know the addressing structureof the underlying machine. ]5A value of integral type or enumeration type can be explicitly converted to a pointer.64) A pointer convertedto an integer of sufficient size (if any such exists on the implementation) and back to the same pointer typewill have its original value; mappings between pointers and integers are otherwise implementation-defined.6A pointer to a function can be explicitly converted to a pointer to a function of a different type.
The effectof calling a function through a pointer to a function type (8.3.5) that is not the same as the type used in thedefinition of the function is undefined. Except that converting an rvalue of type “pointer to T1” to the type“pointer to T2” (where T1 and T2 are function types) and back to its original type yields the originalpointer value, the result of such a pointer conversion is unspecified. [Note: see also 4.10 for more details of__________________63) Function types (including those used in pointer to member function types) are never cv-qualified; see 8.3.5 .64) Converting an integral constant expression (5.19) with value zero always yields a null pointer (4.10), but converting other expressions that happen to have value zero need not yield a null pointer.73ISO/IEC 14882:1998(E)5.2.10 Reinterpret cast© ISO/IEC5 Expressionspointer conversions.
]7A pointer to an object can be explicitly converted to a pointer to an object of different type.65) Except thatconverting an rvalue of type “pointer to T1” to the type “pointer to T2” (where T1 and T2 are object typesand where the alignment requirements of T2 are no stricter than those of T1) and back to its original typeyields the original pointer value, the result of such a pointer conversion is unspecified.8The null pointer value (4.10) is converted to the null pointer value of the destination type.9An rvalue of type “pointer to member of X of type T1” can be explicitly converted to an rvalue of type“pointer to member of Y of type T2” if T1 and T2 are both function types or both object types.66) The nullmember pointer value (4.11) is converted to the null member pointer value of the destination type. Theresult of this conversion is unspecified, except in the following cases:— converting an rvalue of type “pointer to member function” to a different pointer to member functiontype and back to its original type yields the original pointer to member value.— converting an rvalue of type “pointer to data member of X of type T1” to the type “pointer to data member of Y of type T2” (where the alignment requirements of T2 are no stricter than those of T1) and backto its original type yields the original pointer to member value.10An lvalue expression of type T1 can be cast to the type “reference to T2” if an expression of type “pointerto T1” can be explicitly converted to the type “pointer to T2” using a reinterpret_cast.
That is, areference cast reinterpret_cast<T&>(x) has the same effect as the conversion*reinterpret_cast<T*>(&x) with the built-in & and * operators. The result is an lvalue that refersto the same object as the source lvalue, but with a different type. No temporary is created, no copy is made,and constructors (12.1) or conversion functions (12.3) are not called.67)5.2.11 Const cast[expr.const.cast]1The result of the expression const_cast<T>(v) is of type T. If T is a reference type, the result is anlvalue; otherwise, the result is an rvalue and, the lvalue-to-rvalue (4.1), array-to-pointer (4.2), andfunction-to-pointer (4.3) standard conversions are performed on the expression v. Types shall not bedefined in a const_cast.
Conversions that can be performed explicitly using const_cast are listedbelow. No other conversion shall be performed explicitly using const_cast.2[Note: Subject to the restrictions in this section, an expression may be cast to its own type using aconst_cast operator. ]3For two pointer types T1 and T2 whereT1 is cv 1 , 0 pointer to cv 1 , 1 pointer to .