类中函数前、后、参数加const

1、参数加const:int fun(const int a)

a在函数里不可被修改

2、函数前加const:const int* const fun()

这种一般是返回的指针或者是引用,加const是规定返回值不可被修改

3、函数后加const:int fun()const

这个函数不能访问类中所有this所能调用的内存,即这是个只读函数

原文地址:https://www.cnblogs.com/judes/p/9778036.html