c++中,const是什么意思,const声明的是什么

来源:百度知道 编辑:UC知道 时间:2024/06/08 02:05:52

常量申明,如:
const double PI = 3.14;
申明双精度浮点常数。
const char *str = "hello world";

char const *str ="hello world";
申明char型指针,指向字符串常量
char a[10];
char * const str str = a;
申明一个char型常量指针,指向a的地址

class T
{
public:
double val() const{ return val_; } //对函数的修饰,表示类的数据成员值,在该函数中不能被改变
private:
double val_;
}

http://zhidao.baidu.com/question/8105376.html?md=3

声明的是一种不可改变的值.