const_cast также можно использовать для добавления константности.
$5.2.11/3 - "For two pointer types T1 and T2 where
T1 is cv1 , 0 pointer to cv1 , 1 pointer to . . . cv1 ,n − 1 pointer to cv1 ,n T
and
T2 is cv2 , 0 pointer to cv2 , 1 pointer to . . . cv2 ,n − 1 pointer to cv2 ,n T
where T is any object type or the void type and where cv1 ,k and cv2 ,k may be different cv-qualifications, an rvalue of type T1 may be explicitly converted to the type T2 using a const_cast. The result of a pointer const_cast refers to the original object.
Обратите внимание:
int *t1 = NULL; // T = int, cv1, 0 = none
int * const t2 = const_cast<int * const>(t1); // T = int, cv2, 0 = const
Согласно приведенной выше цитате, все в порядке, и это добавляет константу к t
Но, как говорит Херб Саттер , в большинстве случаев это явно не требуется.