RAD Studio
ContentsIndex
PreviousUpNext
const_cast (typecast Operator)

Category 

C++-Specific Keywords 

Syntax  

const_cast< T > (arg)

Description 

Use the const_cast operator to add or remove the const or volatile modifier from a type. 

In the statement, const_cast< T > (arg), T and arg must be of the same type except for const and volatile modifiers. The cast is resolved at compile time. The result is of type T. Any number of const or volatile modifiers can be added or removed with a single const_cast expression. 

A pointer to const can be converted to a pointer to non-const that is in all other respects an identical type. If successful, the resulting pointer refers to the original object. 

A const object or a reference to const cast results in a non-const object or reference that is otherwise an identical type. 

The const_cast operator performs similar typecasts on the volatile modifier. A pointer to volatile object can be cast to a pointer to non-volatile object without otherwise changing the type of the object. The result is a pointer to the original object. A volatile-type object or a reference to volatile-type can be converted into an identical non-volatile type.

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!