首页 > 编程语言 > 详细

C++(类型转换 && 常量转换)

时间:2021-04-26 23:16:36      阅读:18      评论:0      收藏:0      [点我收藏+]

C++(类型转换 && 常量转换)

常量转换(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);
}

C++(类型转换 && 常量转换)

原文:https://www.cnblogs.com/lodger47/p/14705065.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!