1、一般一来说,把一个const值赋给一个非const值是可以,如:
const int a = 10;
int b = a;
但是指针例外,如:
const int* a = new int;
int* b = a;//error
可以理解,因为通过指针可以改变内容。
2、class 函数体的const中使用this指针的话,this指针为const this
如:
3、 <<重载
ostream& <<operator(ostream& o,con c) //两处的引用均为必须,因为没有引用会调用拷贝构造函数,而其在ostream是私有的。
{
return o<<c.a;
}