常量转换(const_cast) 不能对非指针 或者非引用的变量进行转换
//常量转换(const_cast)
void test01()
{
const int *p = NULL;
//取出const
int* newp = const_cast<int *>(p);
int* p2 = NULL;
//加上const
const int* newp2 = const_cast<const int*>(p2);
//不能对非指针 或者非引用的变量进行转换
//const int a = 10;
//int b = const_cast<int>(a);
int num = 10;
int &numRef = num;
const int &numRef2 = const_cast<const int&>(numRef);
}
原文:https://www.cnblogs.com/lodger47/p/14705065.html