const_cast

const_cast (const_cast 연산자)

const_cast는 표현식의 const/volatile 속성을 제거하거나 추가하는 캐스트 연산자예요.

출처: cppreference

본문

const_cast는 const 한정을 벗어날 때 사용해요.

const int x = 5;
int& r = const_cast<int&>(x);  // const 제거

정말 필요한 경우에만 써야 하며, 원래 const였던 객체를 수정하면 정의되지 않은 동작이 돼요.

더 알아보기 (Learn more)

cppreference