Pages

Sunday, November 28, 2010

const_cast

* This type of casting manipulates the const attribute of the passed object, either to be set or removed:

Code:

class C {};

const C *a = new C;

C *b = const_cast(a);

Neither of the other three new cast operators can modify the constness of an object.

Notes:

o It is undefined behaviour if the pointer is used to write on an constant object (an object declared as 'const').

o The 'const_cast' operator can also change the 'volatile' qualifier on a type.

No comments: