Static Cast

A CeePlusPlus operator which performs relatively typesafe casts. Spelled:

 static_cast<type>(yo)

All elaborate_cast<> operators have these benefits:

Any C-style typecast can convert to one-and-only-one elaborate_cast<>, but dynamic_cast<> cannot convert to a C-style cast. (If that fails, the C-style typecast will jam raw bits into an lvalue without complaint.)

The types of casts allowed are (some casts are covered by more than one of the below; no complaints please that the list is redundant)

Note also that "typesafe" does NOT exclude undefined behavior: Using static_cast to "downcast" some Base class pointer or reference to one of its Derived classes does not ensure that the referenced object really is of the target class. (Use DynamicCast to add appropriate runtime checks.)


CategoryCpp


EditText of this page (last edited August 19, 2004) or FindPage with title or text search