Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should look at the article <em><a href="http://en.wikibooks.org/wiki/C%2B%2B_Programming/Programming_Languages/C%2B%2B/Code/Statements/Variables/Type_Casting" rel="noreferrer">C++ Programming/Type Casting</a></em>.</p> <p>It contains a good description of all of the different cast types. The following taken from the above link:</p> <blockquote> <p>const_cast</p> <p>const_cast(expression) The const_cast&lt;>() is used to add/remove const(ness) (or volatile-ness) of a variable.</p> <p>static_cast</p> <p>static_cast(expression) The static_cast&lt;>() is used to cast between the integer types. 'e.g.' char->long, int->short etc.</p> <p>Static cast is also used to cast pointers to related types, for example casting void* to the appropriate type.</p> <p>dynamic_cast</p> <p>Dynamic cast is used to convert pointers and references at run-time, generally for the purpose of casting a pointer or reference up or down an inheritance chain (inheritance hierarchy).</p> <p>dynamic_cast(expression)</p> <p>The target type must be a pointer or reference type, and the expression must evaluate to a pointer or reference. Dynamic cast works only when the type of object to which the expression refers is compatible with the target type and the base class has at least one virtual member function. If not, and the type of expression being cast is a pointer, NULL is returned, if a dynamic cast on a reference fails, a bad_cast exception is thrown. When it doesn't fail, dynamic cast returns a pointer or reference of the target type to the object to which expression referred.</p> <p>reinterpret_cast</p> <p>Reinterpret cast simply casts one type bitwise to another. Any pointer or integral type can be casted to any other with reinterpret cast, easily allowing for misuse. For instance, with reinterpret cast one might, unsafely, cast an integer pointer to a string pointer.</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload