C++ 中有四種 Cast:const_cast、static_cast、dynamic_cast、reinterpret_cast,這些 cast function 不是 marco 也不屬於 STL Libray,是 C++ 的保留字(Keyword)。
const_cast
const_cast 的用途是移除 const 的屬性。
強烈建議不要用,除非有必須。
用法:const_cast<T>(ptr),其中 ptr 必為指標或 refrence
範例如下:
移除 a 的 const 屬性,並且修改 a 的值