摘要: 在数据类型前加上关键字“const”,如const type name=value1,则变量name的值不能更改。但是,name的值并不真的是不可修改的。看这段代码:const int a=100;(int &)a=20;//编译运行都ok此处通过强制类型转换为非常量引用,使得常量a的值可以修改了。但笔者发现下面的代码就是错误的:const int a=100;(int)a=20;//编译error,提示‘=’:左操作数必须为左值更奇怪的是:const float b=0.0;(float)b=1.0;//编译运行,okconst flaot c=0.1;(float&)b=1 阅读全文
posted @ 2013-04-23 22:32 youngzii 阅读(203) 评论(0) 推荐(0) 编辑