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

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

a在函数里不可被修改

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

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

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

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

posted @ 2018-10-12 14:38  朱小勇  阅读(3153)  评论(0编辑  收藏  举报