const表示“只读”的意思
const int a=5; //a的值一直为5
const int *a; //指向常量的指针
int * const a; //指针是常量
类里面的const
class A
{
static void AA() const {}
}
编译出错,因为const只能作用域非静态函数
class A
{
static int a;
int b;
void AA() const {a=2;}
}
class A
{
static int a;
int b;
void AA() const {b=2;}
}
下面这个会编译出错,因为const函数不能修改非静态成员变量的值